I have a java object witch generates this output when i type objectName.toString() :
JavaScript
x
Bus [id=1, nextStationID=0, previousStationID=0]
Is there a JSON parser that lets me make a JSON from the string that my object generates?
something like: JsonObject x = new JsonObject(busObject.toString())
It is important for me to generate it from the string that i get when calling the .toString method.
Any help is appreciated.
Advertisement
Answer
I have fixed my problem by overriding my toString() and printing directly a json object
JavaScript
StringBuilder builder = new StringBuilder();
builder.append("{"id" :");
builder.append(id);
builder.append(", "latitude" :");
builder.append(latitude);
builder.append(", "longitude" :");
builder.append(longitude);
builder.append("}");
return builder.toString();