-2
私はこのjsonオブジェクトを解析するのに助けが必要です。JAONのJSON構文解析android
JSONObject recipe = new JSONObject(buffer.toString());
String cooking_time = recipe.getString("cooking_time_min");
Log.d("cooking_time", cooking_time);
JSONObject directions = recipe.getJSONObject("directions");
JSONObject direction = directions.getJSONObject("direction");
String direction_description = direction.getString("direction_description");
Log.d("desc", direction_description);
JSONObject Ingredients = recipe.getJSONObject("ingredients");
JSONObject ingredient = Ingredients.getJSONObject("ingredient");
所望の出力:
buffer.tostring is = E/Buffer: {"cooking_time_min":"15","directions":{"direction":[{"direction_description":"Preheat oven to 390 °F (2 ...
が、これは私のJavaコードが
"cooking_time_min":"15",
"directions":{
"direction":[
{
"direction_description":"Preheat oven to 390 °F (200 °C).",
"direction_number":"1"
},
{
"direction_description":"Mix together minced lemon rind, lemon juice, chopped parsley, salt and cayenne.",
"direction_number":"2"
},
{
"direction_description":"Rub snapper filets generously with mixture and place in baking dish.",
"direction_number":"3"
},
{
"direction_description":"Place fish in oven and bake for about 10-15 minutes.",
"direction_number":"4"
}
]
},
です:私の現在のJavaコードは、それが唯一の調理時間を解析しています、私が欲しいものをパースされていません私がログに記録しているのは調理時間であり、説明ではありません。
は、調理時間を取得しますが、今、私は別の子を取得する必要がありますし、[OK]をコーディング@Evan –
を働いていないその:
これを試してみてくださいポイントを得た?あなたのコードはオブジェクト 'foodGet'(またはjson-string' builder.toString() ')には存在しないので、子レシピ(' foodGet.getJSONObject( "recipe"); ')を解析できません –
それを宣言すれば、私はできるだろうか?何か –