使用org.json解析JSON [英] Parse JSON with org.json

查看:137
本文介绍了使用org.json解析JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析服务器的输出,如下所示:

I'm trying to parse an output from a server that looks like this:

{
  "GetFolderFilesByZoneResult": [
    {
      "ID": 98748,
      "CreatedBy": "",
      "UpdatedBy": "none",
      "CreatedDate": "\/Date(1308273033620+0100)\/",
      "UpdatedDate": "\/Date(1308303003770+0100)\/",  
      "CommentCount": 0,
      "Key": "",
      "Enabled": true,
      "MimeType": "video",
      "Votes": 2,
      "TotalRating": 0,
      "AllowComments": true,
      "ViewCount": 323,
      "ReleaseDate": "\/Date(1308273000000+0100)\/",
      "ExpireDate": "\/Date(4102444800000+0000)\/",
      "Author": "",
      "Size": 133799936,
      "Tag1": "",
      "Tag2": "",
      "Tag3": "",
      "RecycleBin": false
    },
    {
      "ID": 99107,
      "CreatedBy": "",
      "UpdatedBy": "none",
      "CreatedDate": "\/Date(1308583412520+0100)\/",
      "UpdatedDate": "\/Date(1308583564007+0100)\/",     
      "CommentCount": 0,
      "Key": "",
      "Enabled": true,
      "MimeType": "video",
      "Votes": 0,
      "TotalRating": 0,
      "AllowComments": true,
      "ViewCount": 33,
      "ReleaseDate": "\/Date(1308583380000+0100)\/",
      "ExpireDate": "\/Date(4102444800000+0000)\/",
      "Author": "",
      "Size": 47955968,
      "Tag1": "",
      "Tag2": "",
      "Tag3": "",
      "RecycleBin": false
    }
  ]
}

我正在尝试使用Java org.json来解析它,但我没有任何经验使用JSON / org.json,所以我遇到了一些麻烦。我该如何解析这个?

I'm trying to use Java org.json to parse it, but I don't have any experience with JSON/org.json, so I'm having a little trouble. How can I parse this?

推荐答案

1)假设您的路径上有JSON库(来自www.json.org) ,这很简单。

1) Assuming you have the JSON libraries on your path (from www.json.org), it's pretty easy.

import org.json.JSONTokener;
...

URI uri = new URI("http://someserver/data.json");
JSONTokener tokener = new JSONTokener(uri.toURL().openStream());
JSONObject root = new JSONObject(tokener);

从那里,您可以解决JSON对象的各个部分。看看Javadocs的具体细节。
https://developer.android.com/reference/org /json/package-summary.html

From there, you can address the various parts of the JSON object. Take a look at the Javadocs for the specifics. https://developer.android.com/reference/org/json/package-summary.html

这篇关于使用org.json解析JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆