I am new to the whole concept of Java, so if the title is incorrect, please come with me. I request and return a json string, for this example I will send an example. I am trying to figure out how I would like to work through an array of values and find which is marked as default.
JSON example
{
"id": "333706819617",
"guid": "4aCdriCG0WvfYEUkFf8_xqQEFxgwgNU8",
"title": "Test entry",
"author": "",
"description": "Desc",
"added": 1411702963000,
"content": [
{
"audioChannels": 2,
"audioSampleRate": 44100,
"bitrate": 281656,
"checksums": {
"md5": "70DF3E21131F9F02C3F0A74F3664AB73"
},
"contentType": "audio",
"duration": 43.258,
"expression": "full",
"fileSize": 1522986,
"frameRate": 0.0,
"format": "AAC",
"height": 288,
"isDefault": false,
"language": "en",
"sourceTime": 0.0,
"url": "http://example.com/dZiASoxchRyS",
"width": 352
},
{
"audioChannels": 2,
"audioSampleRate": 44100,
"bitrate": 160000,
"checksums": {
"md5": "3AC622D31B9DED37792CC7FF2F086BE6"
},
"contentType": "audio",
"duration": 43.206,
"expression": "full",
"fileSize": 866504,
"frameRate": 0.0,
"format": "MP3",
"height": 0,
"isDefault": false,
"language": "",
"sourceTime": 0.0,
"url": "http://example.com/59M_PSFgGGXE",
"width": 0
}
],
"thumbnails": [
{
"audioChannels": 0,
"audioSampleRate": 0,
"bitrate": 0,
"checksums": {
"md5": "BE8C98A07B3FE9020BFA464C42112999"
},
"contentType": "image",
"duration": 0.0,
"expression": "full",
"fileSize": 20379,
"frameRate": 0.0,
"format": "JPEG",
"height": 256,
"isDefault": true,
"language": "",
"sourceTime": 0.0,
"url": "http://img.example.com/waveform.jpg",
"width": 256
}
]
}
I take a JSON string and convert it back to JSONObject
JSONObject mediaObject = new Gson().fromJson(mediaString, JSONObject.class);
String content = mediaObject.optString("content");
When I deduce content, it returns the following.
{values=[{nameValuePairs={audioChannels=2.0, audioSampleRate=44100.0, bitrate=281656.0, checksums={nameValuePairs={md5=70DF3E21131F9F02C3F0A74F3664AB73}}......
How to go through the values of the content and find the value isDefault? There is no content in the JSON example, where isDefault = true, therefore, it will be the first object by default.
It seems that I can only orient values as a string, I need to give contenthow JSONArray?
: mediaObject.content JSONArray. mediaObject.optJSONArray("content") null. , JSONArray, .
2: , , json gson, .
, new Gson().toJson(jsonObject); jsonObject.toString()), optJSONArray. JSONObject, JSONObject mediaObject = new JSONObject(mediaString);
GSON