我想从 json 对象中获取 json 对象数组。但它不起作用。有谁能够帮助我?
输出是:
Exception in thread "main" org.json.JSONException: JSONObject["value"] not
found.
Run Code Online (Sandbox Code Playgroud)
源代码:
import org.json.*;
public class JsonIO {
public static void parseJson(StringBuffer sb){
JSONObject obj = new JSONObject(sb);
JSONArray arr = obj.getJSONArray("value");
for (int i = 0; i< arr.length(); i++){
System.out.println(arr.getJSONObject(i).getString("Name"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
输入是:
{ "@odata.context":"https://www.nameofshop......de/odata/$metadata#Product","value":[ { "ProductTypeId":5,"ParentGroupedProductId":0,"VisibleIndividually":true,"Name":"Build your own computer","ShortDescription":"Build it","FullDescription":"<p>Fight back against cluttered workspaces with the stylish IBM zBC12 All-in-One desktop PC, featuring powerful computing resources and a stunning 20.1-inch widescreen display with stunning …Run Code Online (Sandbox Code Playgroud)