简体   繁体   中英

Android Studio Parsing JSON object doesn't work

This is my json file. I am trying to load json in to my recyclerview, but after trying to get the array from the body object it runs on error.

{
body: {
posters: [
{
code: "3292d2r",
attributes: [
"12-plus-trailer",
"2d",
"adventure",
"dubbed",
"dubbed-lang-hu",
"fantasy"
],
featureTitle: "Artemis Fowl",
weight: 0,
dateStarted: "2020-05-28T00:00:00" 

My java code:

public void onResponse(String response) {
                    progressDialog.dismiss();

                try {
                    JSONObject jsonObject=new JSONObject(response);
                    JSONArray jsonArray=jsonObject.getJSONArray("body");

But this method doesn't work, any idea how I can get the items in posters to a JSONARRAY? The JSON file structure:

{
body: {
posters: [
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{}
]
}
}

body is not a JSONArray. It is a JSONObject.

jsonObject.getJSONObject("body").getJSONArray("posters");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM