我有一个JSON格式,我希望使用Java获取值字段,但我无法解决此问题,所以如果有人可以帮助我
我的JSON
[
{
"logic":"and",
"filters":
[
{
"logic":"or",
"filters":
[
{
"field":"BatchPriority",
"operator":"eq",
"value":"1"
},
{
"field":"QPRPriority",
"operator":"eq",
"value":"2"
}
]
}
]
}
]
以下是我如何消费它:
JSONArray jsonFilters = (JSONArray) JSONSerializer.toJSON(jsonFormatted);
我得到了我的JSON,但是我怎样才能获得BatchPriority和QPRPriority字段的值?
JSONArray jsonFilters = new JSONArray(); try { jsonFilters = new JSONArray(jsonFormatted); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JSONArray jsonFiltersNew = new JSONArray(); for (int i = 0; i < jsonFilters.length(); i++) { JSONObject obj; try { jsonFiltersNew = new JSONArray(jsonFilters.getString(i)); List<String> list = new ArrayList<String>(); JSONArray array = jsonFilters.getJSONArray(i); list.add(array.getJSONObject(i).getString("filters")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }