Here is my JSON array.
{ "pidValues":
[{"PID":"12344","associatedSubFeatureID":"1","dashboardName":"CWC"},
{"PID":"12345","associatedSubFeatureID":"1","dashboardName":"WSM"}]
}
我需要在String数组中检索PID的值。 我正在使用泽西框架。
答案 0 :(得分:0)
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");
}
答案 1 :(得分:0)
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 "";
}