How can I concatenate multiple JsonRepresentation Object into one, without building my own string parser?
Say I have two JsonRepresentation objects
obj1 = {"name":"obj1"};
obj2 = {"name":"obj2"};
I would like to get the result concatenation as:
{
{"name":"obj1"},
{"name":"obj2"}
}
Reading the JsonRepresentation, there is no easy w开发者_开发知识库ay to do this except by doing some string manipulation. Am I right?
Thanks
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.
精彩评论