-3

i have below Json to Parse. I am doing it by means of multiple if else loop . is there is any standard way to parse such json format.? Please provide any help..

JSON: 

{
"Info": {
        "DeviceInfo": {
            "Version": "NA",
            "IMEI"   : "NA",
            "IMSI"   : "NA",
            "Manufacture" : "NA",
            "Network"     : "NA",
            "Root"        : "NA",
            "Storage"     : "NA"
        },
        "SettingInfo": {
            "Brightness": "NA",
            "FlightMode": "NA"
        },
        "AdvanceInfo": {
            "PictureCount": "NA",
            "VideoCount": "NA",
            "CallIn": "NA",
            "CallOut":"NA"
        },
        "MemoryInfo": {
            "RAM": "NA",
            "ReadSpeedInternal": "NA",
            "WriteSpeedInternal": "NA"
        }
    }
}
KK06
  • 11
  • 1
  • 2

2 Answers2

0

Let the Gson or Jackson libraries do the hard work for you, there is no need to do the parsing yourself,

GSON: https://github.com/google/gson/blob/master/UserGuide.md Jackson: https://github.com/FasterXML/jackson

For further reference see https://dzone.com/articles/be-lazy-productive-android

ScottFree
  • 582
  • 6
  • 23
0

Like this:

String in;
JSONObject reader = new JSONObject(in);

JSONObject info = reader.getJSONObject("Info");
JSONObject deviceInfo = info.getJSONObject("DeviceInfo");
String version = deviceInfo.getString("Version");
String imei = deviceInfo.getString("IMEI");
String imsi = deviceInfo.getString("IMSI");

Here is more information + example:

How to parse JSON in Android

http://www.tutorialspoint.com/android/android_json_parser.htm

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40