views:

72

answers:

1

Hi,

How do I concatenate multiple JsonRepresentation Object into one, without building my own string parser?

Say I have 2 JsonRepresentation objs 
obj1 {"name":"obj1"}
obj2 {"name":"obj2"}

I'd like to get the concatenation:
{
{"name":"obj1"},
{"name":"obj2"}
} 

Reading the JsonRepresentation, there is no easy way to do this except by doing some string manipulation?

Thanks

A: 

If you're referring to this JsonRepresentation class, and you want to merge the 2 objects into an array, then you should be able to do it as follows:

JSONObject jsonObj1 = obj1.toJsonObject();
JSONObject jsonObj2 = obj2.toJsonObject();
JSONArray jsonArray = new JSONArray().append(jsonObj1).append(jsonObj2);
JsonRepresentation jsonConcat = new JsonRepresentation(jsonArray);

Note: I haven't actually used the library, but if it behaves per the API, this should be pretty straightforward.

Kaleb Brasee
thanks! I thought I can do everything without using JSONArray
portoalet