Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gson json parser: value without key

Tags:

java

json

gson

I want to parse a json structure like this:

{"response":
    {
    "arr1":[count,{...}],
    "arr2":[count,{...}]
    }
}

Everything is ok if count have key "count" (for example). But the key is blank. Is it any way to map this structure and manually retrive only this value or i need to parse all of this json myself without gson ?

UPDATED

Here is a valid json (checked with http://jsonlint.com/)

{
    "response": {
        "arr1": [
            615,
            {
                "body": "hi",
                "title": "Re(2):  ..."
            },
            {
                "body": "hello",
                "title": "Re(23):  ..."
            }
        ],
        "arr2": [
            132,
            {
                "body": "hi",
                "title": "Re(2):  ..."
            },
            {
                "body": "hello",
                "title": "Re(23):  ..."
            }
        ]
    }
}
like image 739
dilix Avatar asked May 29 '12 13:05

dilix


People also ask

How to get value from JSON string using Gson?

String myJSONString = "{'test': '100.00'}"; JsonObject jobj = new Gson(). fromJson(myJSONString, JsonObject. class); String result = jobj. get("test").

What is JsonParser in Java?

JsonParser parses JSON using the pull parsing programming model. In this model the client code controls the thread and calls the method next() to advance the parser to the next state after processing each element.

How to convert JsonObject to jsonElement in Java?

We can convert the JsonElement to JsonObject and JsonArray using respective methods: JsonObject jsonObject = jsonElement. getAsJsonObject(); JsonArray jsonArray = jsonElement.


1 Answers

If you want to parse arbitrary collections you should read Serializing and Deserializing Collection with Objects of Arbitrary Types and look at the example code example code.

like image 59
Roger Lindsjö Avatar answered Sep 19 '22 11:09

Roger Lindsjö