JSON data - How to parse?
JSON data - How to parse?
Suppose I have data in JSON. How can I parse the data so I can get the values of nested objects (e.g. kind, id and title)?
kind
id
title
My JSON data is:
"kind": "youtube#playlistItemListResponse",
"items": [
"id": "UExkc1JWcGJNV19LSH",
"items":[
"title": "New Updates",
],
],
1 Answer
1
Well you should remove all the commas since last items should not be followed by one.
So more like:
"kind": "youtube#playlistItemListResponse",
"items": [
"id": "UExkc1JWcGJNV19LSH",
"items": [
"title": "New Updates"
]
]
Other than that you can just use JSONObject lib and extract the value you need. For example to get the kind:
JSONObject jsonObj = new JSONObject(strInput);
String kind = jsonObj.getString("kind"); // kind now contains "youtube#playlistItemListResponse"
where strInput is the above json as a string.
More info: https://developer.android.com/reference/org/json/JSONObject
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thnx alot sir. Its the finalize answer for my this question. Thanks for your precious comment
– Pradeep Sheoran
Aug 29 at 18:52