Skip to content
Advertisement

How do I fetch a JSON array from PHP to my java code?

My JSON response is like this:

JavaScript

Now, I want to add each of the array items into my spinner:

JavaScript

All my spinner items are in double quotes(“”), which I don’t want. I want them in object format. How do I fix this?

EDIT: Tried the following code:

JavaScript

Now, my spinner is completely empty!!

Advertisement

Answer

Your second piece of code is almost correct. Here is the mistake:

JavaScript

Your array is not an array of JSON objects, it is an array of strings directly. Therefore, here is what that line should look like:

JavaScript

(I’m guessing you copied your attempt from this answer, but the question there has an array of objects, and your array is much simpler.)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement