I just came up with challenging problem.
Below is json response where key is variable (a GUID)
How can I parse it? I've tried Google Gson, but that didn't work.
{
"87329751-7493-7329-uh83-739823748596": {
"type": "work",
"status": "online",
"icon": "landline",
"number": 102,
"display_number": "+999999999"
}
}
My guess is that you're looking for a way to get GUID. You could try Object.keys function.
It worked on firefox 21.0, but I cant guaranty that it'll work on every browser.
If you use Gson, in order to parse your response you can create a custom class representing your JSON data, and then you can use a
Map
.Note that a
Map<String, SomeObject>
is exactly what your JSON represents, since you have anobject
, containing a pair ofstring
and someobject
:So, first your class containing the JSON data (in pseudo-code):
Then parse your JSON response using a
Map
, like this:Now you can access all the values using your
Map
, for example:Note: if you only want to get the GUID value, you don't need to create a class
YourClass
, and you can use the same parsing code, but using a genericObject
in theMap
, i.e.,Map<String, Object>
.