简体   繁体   中英

How do I convert a JSON string to a JSON object?

I have problem with converting json string to Json Object

I Receive this Json Result from my server :

{"type":"news","items":[{"id": "867","title": "مخيّم_بساط_الرّيح - مخيّم_كان_ياما_كان","content": " في المركز الجماهيري ابوسنان ..  اليوم الخامس على التوالي .. ","fromDate": false,"toDate": false,"image": "productImages2/105/2017/07/13/image1499940076.jpg","imageAlt": "مخيّم_بساط_الرّيح - مخيّم_كان_ياما_كان","exLink":"http://www.mas.org.il/page.php?type=page&id=2477&ht=#navbar","price": false}]}

and I want to put the result into list view

I have tried many methods which eventually failed

simply you can take that received string as string and then convert it

String json ={"type":"news","items":[{"id": "867","title": "مخيّم_بساط_الرّيح - مخيّم_كان_ياما_كان","content": " في المركز الجماهيري ابوسنان ..  اليوم الخامس على التوالي .. ","fromDate": false,"toDate": false,"image": "productImages2/105/2017/07/13/image1499940076.jpg","imageAlt": "مخيّم_بساط_الرّيح - مخيّم_كان_ياما_كان","exLink":"http://www.mas.org.il/page.php?type=page&id=2477&ht=#navbar","price": false}]}

and now convert in json object

JSONObject jsonObj = new JSONObject(json);

now you can use it as jsonobject

Try this

JSONObject jsonObj = new JSONObject(json);
JSONArray jsonArry = jsonObj.getJSONArray("items");
JSONObject jsonObj1 = jsonArry.getJSONObject(0);
String id = jsonObj1.getString("id");
String title= jsonObj1.getString("title");
..
..
..
String price = jsonObj1.getString("price");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM