Java – use org. Org JSON parsing JSON

I tried to parse the output of a server, which 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,"CreatedDate": "\/Date(1308583412520+0100)\/","UpdatedDate": "\/Date(1308583564007+0100)\/","Votes": 0,"ViewCount": 33,"ReleaseDate": "\/Date(1308583380000+0100)\/","Size": 47955968,"RecycleBin": false
    }
  ]
}

I tried to use Java. Org JSON to parse it, but I'm interested in JSON / org JSON doesn't have any experience, so I'm in trouble How can I parse it?

Solution

1) Suppose you have a JSON library on your path (from www.json. ORG), which is very simple

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

From there, you can solve the various parts of JSON objects Take a look at the details of JavaDocs https://developer.android.com/reference/org/json/package-summary.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>