如何在Android中解析json字符串? [英] How to parse json string in Android?
本文介绍了如何在Android中解析json字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
Android/Java 中的 JSON 数组迭代
我正在从服务器获取 JSON 字符串,并且我已经通过代码获取了 JSON 字符串.但我不明白如何解析它.
I am fetching JSON string from server and I have already got JSON string by code. But I didn't understand how to parse it.
下面是我的 JSON 字符串
Below is my JSON string
{
"university": {
"name": "oxford",
"url": "http://www.youtube.com"
},
"1": {
"id": "2",
"title": "Baseball",
"datetime": "2011-11-11 10:41:46"
},
"2": {
"id": "1",
"title": "Two basketball team players earn all state honors",
"datetime": "2011-11-11 10:40:57"
}
}
请提供任何指导或代码片段.
Please provide any guidance or code snippet.
推荐答案
使用 JSON 类进行解析,例如
Use JSON classes for parsing e.g
JSONObject mainObject = new JSONObject(Your_Sring_data);
JSONObject uniObject = mainObject.getJSONObject("university");
String uniName = uniObject.getString("name");
String uniURL = uniObject.getString("url");
JSONObject oneObject = mainObject.getJSONObject("1");
String id = oneObject.getString("id");
....
这篇关于如何在Android中解析json字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文