java – 使用org.json解析JSON

前端之家收集整理的这篇文章主要介绍了java – 使用org.json解析JSON前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图解析一个服务器的输出,看起来像这样:
{
  "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,"CreatedDate": "\/Date(1308583412520+0100)\/","UpdatedDate": "\/Date(1308583564007+0100)\/","Votes": 0,"ViewCount": 33,"ReleaseDate": "\/Date(1308583380000+0100)\/","Size": 47955968,"RecycleBin": false
    }
  ]
}

我试图使用Java org.json来解析它,但是我对JSON / org.json没有任何经验,所以我有点麻烦.我该如何解析?

解决方法

1)假设你的路径上有JSON库(来自www.json.org),这很简单.
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

原文链接:https://www.f2er.com/java/124270.html

猜你在找的Java相关文章