-1

I can’t get the JSON data of message using swiftyjson. When i print JSON value is there. But, when i print(json["result"]["message"]) it is null

    {
    "result": [{

        "message": "success",
        "age": "25"

    }]
 }



let json = JSON(data:jdata)
                print(json)
                print(json["result"]["message"])
1
  • Looks to me as if result is an array, so you would need something like print(json["result"][0]["message"]) to access the zeroth element of the array (ie the first message). Commented Jul 3, 2017 at 12:46

3 Answers 3

2

json["result"] seems to be an array, you have to cast it to array like

let array = json["result"].arrayValue
let message = array[0]["message"]
Sign up to request clarification or add additional context in comments.

Comments

1

You result is of array type. And you have to set index of object.

Try:

var array = json["result"].arrayValue

print(array[0]["message"])

You can also check this question

Hope it helps

Comments

0

Try:

let json = JSON(data: jdata)

let message = json["result"].array?.first?["message"]

print(message)

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.