如何从json-array获取内部数组值

时间:2015-06-16 05:14:16

标签: java android json

这是json的回应:

[
    {
        "currentvalue": [
            {
                "id": "13",
                "current_value": "0,1",
                "create_date": "2015-06-15 06:12:14",
                "status": "0",
                "modify_date": "0000-00-00 00:00:00",
                "entry_time": "",
                "indicator_id": "13",
                "member_id": "9"
            }
        ],
        "target": {
            "notification_time": "06:12:14",
            "id": "13",
            "health_selected_days": {
                "day": "3"
            },
            "point": "1",
            "indicator_name": "Test2",
            "create_date": "2015-06-15 06:12:14",
            "indicator_status": "0",
            "notification_type": "0",
            "modify_date": "2015-06-15 06:12:14",
            "indicator_measure": "0",
            "target_value": "0,1",
            "total_point": "0",
            "member_id": "9"
        }
    },
    {
        "currentvalue": [
            {
                "id": "12",
                "current_value": "0,1",
                "create_date": "2015-06-15 04:56:22",
                "status": "0",
                "modify_date": "0000-00-00 00:00:00",
                "entry_time": "",
                "indicator_id": "12",
                "member_id": "9"
            }
        ],
        "target": {
            "notification_time": "02:02:00",
            "id": "12",
            "health_selected_days": {
                "day": ""
            },
            "point": "1",
            "indicator_name": "Ashish",
            "create_date": "2015-06-15 04:56:22",
            "indicator_status": "0",
            "notification_type": "0",
            "modify_date": "2015-06-15 04:56:22",
            "indicator_measure": "0",
            "target_value": "0,1",
            "total_point": "0",
            "member_id": "9"
        }
    },
    {
        "currentvalue": [
            {
                "id": "11",
                "current_value": "0,1",
                "create_date": "2015-06-12 13:58:09",
                "status": "0",
                "modify_date": "0000-00-00 00:00:00",
                "entry_time": "",
                "indicator_id": "11",
                "member_id": "9"
            }
        ],
        "target": {
            "notification_time": "02:02:00",
            "id": "11",
            "health_selected_days": {
                "day": "1,2,3,4,5,6,7,"
            },
            "point": "123",
            "indicator_name": "A",
            "create_date": "2015-06-12 13:58:09",
            "indicator_status": "0",
            "notification_type": "0",
            "modify_date": "2015-06-12 13:58:09",
            "indicator_measure": "0",
            "target_value": "0,1",
            "total_point": "0",
            "member_id": "9"
        }
    }
]

如何从“target”数组中获取indicator_name值:

5 个答案:

答案 0 :(得分:0)

    JSONParser parser = new JSONParser();

    Object obj = parser.parse(new FileReader("your file path"));

    JSONObject jsonObject = (JSONObject) obj;

    String name = (String) jsonObject.get("indicator_name");
    System.out.println(name);

你可以这样试试。

答案 1 :(得分:0)

for(int i=0; i<jsonArray.length(); i++)
{
    JSONObject object = jsonArray.getJSONObject(i);
    JSONObject target = object.getJSONObject("target");
    String indicator_name = target.getString("indicator_name");
}

target不是数组,实际上它是一个JSONObject。 this site可能有助于使json数据看起来更清晰。

答案 2 :(得分:0)

你可以这样做。

try {
                    JSONArray _jArrayMain = new JSONArray("YOURJSONSTRING");
                    for (int i = 0; i < _jArrayMain .length(); i++) {
                        JSONObject _jObj = _jArrayMain.getJSONObject(i);
                        JSONObject   _jObjTarget = _jObj.getJSONObject("target");
                        String _indicator_name = _jObjTarget.getString("indicator_name");
                        System.out.println("Indicator Name : " + _indicator_name);
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

答案 3 :(得分:0)

您可以使用以下代码段。

final JSONArray jsonArray = new JSONArray("JSON_STRING");
for (JSONObject jObject: jsoonArray) {
     final JSONObject   jsonTargetObject = jObject.optJSONObject("target");
     if(jsonTargetObject != NULL) {
     final String indicatorName = jsonTargetObject.optString("indicator_name", null);
     System.out.println("Indicator Name : " + indicatorName);
}

答案 4 :(得分:0)

在您的示例中,

<script src="js/jquery.js"></script>
<script src="js/typed.js"></script>
<script>
  $(function() {
    $(".element").typed({
      image: ['images_folder/foo.png', 'images_folder/bar.png'],
      typeSpeed: 30
    });
  });
</script>
相关问题