English 中文(简体)
Concatenate JsonRepresentation
原标题:

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 way 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.

问题回答

暂无回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签