0
こんにちは、Json Simpleを使用して「チーズ」の項目を選択しようとしていますが、選択しようとすると「null」が戻っているようです。 ?ここでこれを行う方法のいくつかのアドバイスを持っている優れただろう `JsonSimple:Jsonフィードで2番目のオブジェクトを取得する方法
は、JSONのサンプルです:
String s="[\"coins\",{\"wallet\":{\"shoppinglist\":{\"cheese\":{\"ingrediants\":[\"milk\",{\"preservative1\":\"wax\"}]}}}}]";
、ここではコードです:
System.out.println(s);
System.out.println("=======decode=======");
Object obj=JSONValue.parse(s);
JSONArray array=(JSONArray)obj;
System.out.println("======the 2nd element of array======");
System.out.println(array.get(1));
System.out.println();
System.out.println("======the 1st element of array======");
System.out.println(array.get(0));
System.out.println();
JSONObject obj2=(JSONObject)array.get(1);
System.out.println("======field \"1\"==========");
System.out.println(obj2.get("wallet"));
JSONObject obj3=(JSONObject) obj2.get("shoppinglist");
System.out.println("======field \"2\"==========");
System.out.println(obj3); //This figure is returning null when I would like it to return the json object shopping list
それが現在出力:
を["coins",{"wallet":{"shoppinglist":{"cheese":{"ingrediants":["milk",{"preservative1":"wax"}]}}}}] =======decode======= ======the 2nd element of array====== {"wallet":{"shoppinglist":{"cheese":{"ingrediants":["milk",{"preservative1":"wax"}]}}}} ======the 1st element of array====== coins ======field "1"========== {"shoppinglist":{"cheese":{"ingrediants":["milk",{"preservative1":"wax"}]}}} ======field "2"========== null
のために私のレッスンを教えるということ:Smartyのことをしようと私のsystem.outsで仕事をしているし、良い名前と私の変数の命名ないため
が意図した結果を得るために、これは使用しています。学んだ教訓! - ありがとう! –