android - 如何在Android中解析json字符串?

这个问题在这里已经有了答案:
关闭10年前.

Possible Duplicate:
JSON Array iteration in Android/Java

我正在从服务器获取 JSON 字符串,并且我已经通过代码获取了 JSON 字符串。 但是我不明白如何解析它。

下面是我的 JSON 字符串

{
    "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"
    }
}

请提供任何指导或代码 fragment 。

最佳答案

使用 JSON 类进行解析,例如

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");
....

https://stackoverflow.com/questions/8091051/

相关文章:

php - 带有双引号的json解析错误

java - Retrofit2 安卓 : Expected BEGIN_ARRAY but was

jquery - 如何获取 JSON 键和值?

json - 如何从 nginx 生成 JSON 日志?

c# - 判断 Json 结果是对象还是数组

python - 在 Python 中将 JSON 转换为字符串

python - python中的 pretty-print json(pythonic方式)

ios - Swift读取远程通知的userInfo

java - 在 Java 中将 JSON 转换为 XML

wcf - 在 wcf 中返回原始 json(字符串)