org.json

Parse JSON with org.json [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-11-27 03:11:22
问题 This question already has an answer here: How to parse JSON in Java 31 answers 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

The difference between getString() and optString() in Json

和自甴很熟 提交于 2019-11-26 12:06:25
问题 What is the difference between getString() and optString() in JSON? 回答1: As Diego mentions, it's a good idea to check the documentation (this link is now out of date - good thing we have the Wayback Machine!) before posting a question here, but now that you have: The difference is that optString returns the empty string ( "" ) if the key you specify doesn't exist. getString on the other hand throws a JSONException . Use getString if it's an error for the data to be missing, or optString if