0

I'm trying to update the status of User 2 to DONE

I got this JSON array

[
    {
        "id":"YWauEwCUIe",
        "name":"User 1",
        "status":"DONE"
    },
    {
        "id":"JgwCjgvU5b",
        "name":"User 2",
        "status":"WAIT"
    }
]

I tried with this code, but it not going to work.

mUsers[0][status] = "DONE";
3
  • Welcome to Stack Overflow. Did you try mUsers[0]["status"] = "DONE"; instead? It would help if you could provide a minimal reproducible example rather than just a line of code, and explain exactly what happens with what you've tried, rather than just "it not going to work". Commented Nov 15, 2019 at 13:36
  • I tried with ['status'] and now try ["status"] and it worked. BTW Thanks. Commented Nov 15, 2019 at 13:43
  • 1
    Single quotes are for literal values of char type, whereas double quotes are for string. That's why double quotes work and single quotes don't. Commented Nov 15, 2019 at 13:53

2 Answers 2

1

With [0] you are changing the status of "User 1"
For "User 2" you need to use [1] and also write "status" between quotation marks

 mUsers[1]["status"] = "DONE";

Regards.

Sign up to request clarification or add additional context in comments.

Comments

0

Provide the name status as a String in the JSON-Array like this:

mUsers[0]["status"] = "DONE";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.