小编mar*_*_ll的帖子

如何从特定索引开始迭代数组?

我想开始从特定索引迭代一个数组.我怎样才能做到这一点?

myj.each do |temp| 
###
end
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

5
推荐指数
2
解决办法
1240
查看次数

如何从 JSON 对象获取数组?

我想从 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)

java json

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

json ×1

ruby ×1

ruby-on-rails ×1