0

Got the output result in json nested array.

Help to access the USER-id of this json format .

var result = {
    "USER": {
        "id": "11456",
        "email": "[email protected]",
        "name": "g"
    },
    "status": "true",
    "group-title": "title",
    "group-name": "2-Group"
}
5
  • 1
    the provided json is in wrong format. Check it on json.parser.online.fr Commented May 3, 2017 at 5:36
  • It should be like this {"status":"true","USER":{"id":"11456","name":"g","email":"[email protected]"}, "group-name":"2-Group","group-title":"title"} Commented May 3, 2017 at 5:38
  • access the userid like console.log(result.USER.id) Commented May 3, 2017 at 5:39
  • Mentioned json is in wrong format. How do you create this json. ?? Please edit your question with proper json Commented May 3, 2017 at 5:39
  • Do you want to use this json in php or js Commented May 3, 2017 at 5:40

3 Answers 3

1

I thin your json structue is wrong. Below is the corrected structure

{
  "status": "true",
  "USER": {
    "id": "11456",
    "name": "g",
    "email": "g@‌​gmail.com"
  },
  "group-name": "2-Group",
  "group-title": "title"
}

The json usages in JS

 var result={  "status": "true",  "USER": {    "id": "11456",    "name": "g",    "email": "g@‌​gmail.com"  },  "group-name": "2-Group",  "group-title": "title"};
resultJson=jQuery.parseJSON(result);

var userId=resultJson.USER.id; // here you will get the user id

Please try this way. This may help you. Don't forget to add jQuery in your script

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

Comments

0

json values are not seperated by

 ;

the correct formate for your json is

var result =  {"status":"true","USER":{"id":"11456","name":"g","email":"[email protected]"},
                "group-name":"2-Group","group-title":"title"}

for this formate u can assess the user id by

    result.USER.id;

Comments

0
From your code, you can directly access Id as below:

<script>
var result = {
    "USER": {
        "id": "11456",
        "email": "[email protected]",
        "name": "g"
    },
    "status": "true",
    "group-title": "title",
    "group-name": "2-Group"
};

alert(result.USER.id);
</script>

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.