[英]Json object inside array inside json object using kotlin or java
[英]how to read json object inside json array using jersy in java?
Here is my JSON array.
{ "pidValues":
[{"PID":"12344","associatedSubFeatureID":"1","dashboardName":"CWC"},
{"PID":"12345","associatedSubFeatureID":"1","dashboardName":"WSM"}]
}
我需要在字符串数组中检索 PID 的值。 我正在使用球衣框架。
JSONObject data = new JSONObject(your_JSON_Repsonse);
JSONArray data_pidValues=data.getJSONArray(pidValues);
for(int i=0;i<=data_pidValues.length();i++)
{
PID=data_pidValues.getString("PID");
associatedSubFeatureID=data_pidValues.getString("associatedSubFeatureID");
dashboardName=data_pidValues.getString("dashboardName");
}
As I am using jersey the method you suggested above doesn't work. I used below code to parse.
@Path("/any")
@Consumes("application/json")
public String getAllData(JSONArray pidValues)
{
String [] accessiblepid = new String[pidValues.size()];
LinkedHashMap<String, String> mapList = new LinkedHashMap<String, String>();
String subProgId="";
JSONArray jsonArray = new JSONArray();
JSONArray jsonArrayPid = new JSONArray();
for (int i=0; i<pidValues.size();i++)
{
System.out.println(pidValues.get(i));
mapList =(LinkedHashMap<String, String>) pidValues.get(i);
System.out.println(mapList.get("PID"));
accessiblepid[i] = mapList.get("PID").toString();
jsonArray.add(mapList.get("dashboardName").toString());
jsonArrayPid.add(mapList.get("PID").toString());
subProgId=mapList.get("associatedSubFeatureID");
}
return "";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.