Я пытаюсь создать программу, которая использует информационный API MLB, расположенный здесь . Я могу получить всю информацию об игроке, но не могу получить метод toString () для получения более конкретной информации из ответа json.
Ответ:
{"search_player_all":{"copyRight":" Copyright 2019 MLB Advanced Media, L.P. Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt ","queryResults":{"totalSize":"1","created":"2019-05-28T12:34:47","row":{"college":"","pro_debut_date":"2012-09-05T00:00:00","birth_city":"Amsterdam","name_display_first_last":"Didi Gregorius","birth_date":"1990-02-18T00:00:00","height_inches":"3","team_id":"147","birth_state":"","name_last":"Gregorius","active_sw":"Y","birth_country":"Netherlands","bats":"L","player_id":"544369","service_years":"","name_display_last_first":"Gregorius, Didi","name_first":"Didi","league":"AL","weight":"205","name_use":"Didi","sport_code":"mlb","throws":"R","high_school":"","team_code":"nya","team_full":"New York Yankees","team_abbrev":"NYY","height_feet":"6","position":"SS","name_display_roster":"Gregorius","position_id":"6"}}}}
Мой код для обработки json:
JSONObject responsejson = response.getBody().getObject();
String test = responsejson.getString("copyRight");
Примечание. Я использую org.json.JSONObject для обработки.
Я надеюсь, что он вернется:
Copyright 2019 MLB Advanced Media, L.P. Use of any content on this
page acknowledges agreement to the terms posted here
http://gdx.mlb.com/components/copyright.txt
но вместо этого я просто получаю:
Exception in thread "main" org.json.JSONException: JSONObject["copyRight"] not found.
Любая помощь приветствуется.
Редактировать: Как уже отмечали другие, copyRight не является записью верхнего уровня, однако, когда я пытаюсь получить getString ("search_player_all"), я получаю эту ошибку:
Exception in thread "main" org.json.JSONException: JSONObject["search_player_all"] not a string.
Решение: я использовал .getJSONObject (), чтобы перейти к уровню строки. Спасибо за помощь