简体   繁体   English

如何将JSON字符串转换为JSON对象?

[英]How do I convert a JSON string to a JSON object?

I have problem with converting json string to Json Object 我在将json字符串转换为Json Object时遇到问题

I Receive this Json Result from my server : 我从服务器收到此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 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 现在转换为json对象

JSONObject jsonObj = new JSONObject(json);

now you can use it as jsonobject 现在您可以将其用作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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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