如何解析JSOn DATA

时间:2017-05-04 09:11:28

标签: android json

[
  {
    "ORDERID": [
      "Epp144534354354",
      "Epp14453sdfgsfd",
      "Epp14487484",
      "Epp144454464646"
    ],
    "ADDRESS": " MUMBAI",
    "FOLLOW_UPDATE": "25/5/2017",
    "SIGN_IMAGE": "sign.png",
    "DATE_TIME": "2017-05-02 17:52:09.0",
    "EMAIL": "abhi@abhi.con",
    "IMAGE_1": "image1.jpg",
    "COMMENT": "gshshshsh",
    "IMAGE_3": "image3.jpg",
    "NAME": "abhi",
    "MOBILE": "22416545",
    "IMAGE_2": "image2.jpg"
  }
]

我想解析上面的json数据然后如何解析android中的json如何解析java中的代码

2 个答案:

答案 0 :(得分:2)

你可以试试这个。这是在android中的JSON解析。

 String response=" [\n" +
            "{ \"ORDERID\": [ \"Epp144534354354\", \"Epp14453sdfgsfd\", \"Epp14487484\", \"Epp144454464646\"],\n" +
            "\n" +
            "\"ADDRESS\": \" 26, Wakad Road Samarth Colony, Omkar Society, Pimple Nilakh Pimpri-Chinchwad, Maharashtra 411027\",\n" +
            "\n" +
            "\"FOLLOW_UPDATE\": \"25/5/2017\",\n" +
            "\n" +
            "\"SIGN_IMAGE\": \"http://192.168.0.108:8084/MarketingApplicationImages/IMAGES//sign.png\",\n" +
            "\n" +
            "\"DATE_TIME\": \"2017-05-02 17:52:09.0\",\n" +
            "\n" +
            "\"EMAIL\": \"abhi@abhi.con\",\n" +
            "\n" +
            "\"IMAGE_1\": \"http://192.168.0.108:8084/MarketingApplicationImages/IMAGES//image1.jpg\",\n" +
            "\n" +
            "\"COMMENT\": \"gshshshsh\",\n" +
            "\n" +
            "\"IMAGE_3\": \"http://192.168.0.108:8084/MarketingApplicationImages/IMAGES//image3.jpg\",\n" +
            "\n" +
            "\"NAME\": \"abhi\",\n" +
            "\n" +
            "\"MOBILE\": \"8149608493\",\n" +
            "\n" +
            "\"IMAGE_2\": \"http://192.168.0.108:8084/MarketingApplicationImages/IMAGES//image2.jpg\"\n" +
            "  }]";

    try {
        JSONArray jArray=new JSONArray(response);
        for (int i = 0; i <jArray.length() ; i++) {
            JSONObject jonj=jArray.getJSONObject(i);
            JSONArray orderArray=jonj.getJSONArray("ORDERID");
            for (int j = 0; j <orderArray.length(); j++) {

                Log.e("array value"," .....   "+orderArray.getString(i));

            }
            Log.e("address"," .....   "+jonj.getString("ADDRESS"));
            Log.e("FOLLOW_UPDATE"," .....   "+jonj.getString("FOLLOW_UPDATE"));
            Log.e("SIGN_IMAGE"," .....   "+jonj.getString("SIGN_IMAGE"));

        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

答案 1 :(得分:0)

要解析json,请遵循以下基本规则,这些规则将为您提供长期帮助。

  1. 首先检查json是否有效,paste your json response and click validate json.

  2. 以正确的格式查看json内容,以便更好地使用paste your data in text section and switch to view section to view it.

  3. 然后使用GSON库来解析数据(参考任何在线教程)

  4. 您需要使用pojo来使用GSON paste json response in the text box section which is located on the left hand side and then on the right hand side set source type as JSON annotation type as GSON and click on the preview at the bottom of the page, copy it and use it.