Мне нужна помощь в анализе этого объекта json. Мой текущий код Java не разборе, что я хочу, это только разборе время приготовления:JSON Parse in JAVA android
"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-код:
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 ...
но все, что я получаю в своем журнале, - это время приготовления, а не описание.
, что является правильным, и из-за этого food.Get.getString получает время приготовления пищи, но теперь мне нужно, чтобы получить еще одного ребенка, и он не работает –
@Evan кодирования нормально, вы понял? Ваш код не может проанализировать дочерний рецепт ('foodGet.getJSONObject (« recipe »);'), потому что он не существует в объекте 'foodGet' (или в json-string' builder.toString() ') –
, поэтому я должен просто объявите его там, а потом я смогу? или что –