Getting values from JSON multidimensional array?












-1















I have a JSON array that looks like this:



{
"id": 258,
"rawId": null,
"displayName": null,
"name": {
"givenName": "my ame",
"honorificSuffix": "",
"formatted": "my ame",
"middleName": "",
"familyName": "",
"honorificPrefix": ""
},
"nickname": "",
"phoneNumbers": [{
"value": "23423442342424",
"pref": false,
"id": 0,
"type": "mobile"
}],
"emails": null,
"addresses": null,
"ims": null,
"organizations": [{
"pref": "false",
"title": "",
"name": "",
"department": "",
"type": null
}],
"birthday": null,
"note": "",
"photos": null,
"categories": null,
"urls": null
}


I need to get the phoneNumbers >> value from this JSON.



SO I TRIED SOMETHING LIKE THIS:



var d = JSON.parse(test);
alert(test[0].phoneNumbers.value);



The variable test is the JSON shown above.



and I also tried:



alert(d[0].phoneNumbers.value);



and



alert(test.phoneNumbers.value);



But none of the above work.



Is there something that I am missing in my code?



Thanks in advance.










share|improve this question




















  • 6





    d.phoneNumbers[0].value

    – Robin Zigmond
    Jan 2 at 16:13






  • 1





    phoneNumbers is an array so you should iterate that to get the value.

    – Alex G
    Jan 2 at 16:13
















-1















I have a JSON array that looks like this:



{
"id": 258,
"rawId": null,
"displayName": null,
"name": {
"givenName": "my ame",
"honorificSuffix": "",
"formatted": "my ame",
"middleName": "",
"familyName": "",
"honorificPrefix": ""
},
"nickname": "",
"phoneNumbers": [{
"value": "23423442342424",
"pref": false,
"id": 0,
"type": "mobile"
}],
"emails": null,
"addresses": null,
"ims": null,
"organizations": [{
"pref": "false",
"title": "",
"name": "",
"department": "",
"type": null
}],
"birthday": null,
"note": "",
"photos": null,
"categories": null,
"urls": null
}


I need to get the phoneNumbers >> value from this JSON.



SO I TRIED SOMETHING LIKE THIS:



var d = JSON.parse(test);
alert(test[0].phoneNumbers.value);



The variable test is the JSON shown above.



and I also tried:



alert(d[0].phoneNumbers.value);



and



alert(test.phoneNumbers.value);



But none of the above work.



Is there something that I am missing in my code?



Thanks in advance.










share|improve this question




















  • 6





    d.phoneNumbers[0].value

    – Robin Zigmond
    Jan 2 at 16:13






  • 1





    phoneNumbers is an array so you should iterate that to get the value.

    – Alex G
    Jan 2 at 16:13














-1












-1








-1








I have a JSON array that looks like this:



{
"id": 258,
"rawId": null,
"displayName": null,
"name": {
"givenName": "my ame",
"honorificSuffix": "",
"formatted": "my ame",
"middleName": "",
"familyName": "",
"honorificPrefix": ""
},
"nickname": "",
"phoneNumbers": [{
"value": "23423442342424",
"pref": false,
"id": 0,
"type": "mobile"
}],
"emails": null,
"addresses": null,
"ims": null,
"organizations": [{
"pref": "false",
"title": "",
"name": "",
"department": "",
"type": null
}],
"birthday": null,
"note": "",
"photos": null,
"categories": null,
"urls": null
}


I need to get the phoneNumbers >> value from this JSON.



SO I TRIED SOMETHING LIKE THIS:



var d = JSON.parse(test);
alert(test[0].phoneNumbers.value);



The variable test is the JSON shown above.



and I also tried:



alert(d[0].phoneNumbers.value);



and



alert(test.phoneNumbers.value);



But none of the above work.



Is there something that I am missing in my code?



Thanks in advance.










share|improve this question
















I have a JSON array that looks like this:



{
"id": 258,
"rawId": null,
"displayName": null,
"name": {
"givenName": "my ame",
"honorificSuffix": "",
"formatted": "my ame",
"middleName": "",
"familyName": "",
"honorificPrefix": ""
},
"nickname": "",
"phoneNumbers": [{
"value": "23423442342424",
"pref": false,
"id": 0,
"type": "mobile"
}],
"emails": null,
"addresses": null,
"ims": null,
"organizations": [{
"pref": "false",
"title": "",
"name": "",
"department": "",
"type": null
}],
"birthday": null,
"note": "",
"photos": null,
"categories": null,
"urls": null
}


I need to get the phoneNumbers >> value from this JSON.



SO I TRIED SOMETHING LIKE THIS:



var d = JSON.parse(test);
alert(test[0].phoneNumbers.value);



The variable test is the JSON shown above.



and I also tried:



alert(d[0].phoneNumbers.value);



and



alert(test.phoneNumbers.value);



But none of the above work.



Is there something that I am missing in my code?



Thanks in advance.







javascript json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 18:25









skellertor

360217




360217










asked Jan 2 at 16:11









James JuanjieJames Juanjie

738




738








  • 6





    d.phoneNumbers[0].value

    – Robin Zigmond
    Jan 2 at 16:13






  • 1





    phoneNumbers is an array so you should iterate that to get the value.

    – Alex G
    Jan 2 at 16:13














  • 6





    d.phoneNumbers[0].value

    – Robin Zigmond
    Jan 2 at 16:13






  • 1





    phoneNumbers is an array so you should iterate that to get the value.

    – Alex G
    Jan 2 at 16:13








6




6





d.phoneNumbers[0].value

– Robin Zigmond
Jan 2 at 16:13





d.phoneNumbers[0].value

– Robin Zigmond
Jan 2 at 16:13




1




1





phoneNumbers is an array so you should iterate that to get the value.

– Alex G
Jan 2 at 16:13





phoneNumbers is an array so you should iterate that to get the value.

– Alex G
Jan 2 at 16:13












1 Answer
1






active

oldest

votes


















1














What you showed us is a JSON string (giving a JS object after parsing), not an array.



So d[0].phoneNumbers will not work and d.phoneNumbers will work and will give you an array.



And because it will give you an array, d.phoneNumbers.value will not work, and d.phoneNumbers[0].value will.






share|improve this answer





















  • 1





    test is the original string, the OP has given the name d to the object formed by parsing it

    – Robin Zigmond
    Jan 2 at 16:33











  • Corrected, thanks

    – iArcadia
    Jan 2 at 16:35











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009583%2fgetting-values-from-json-multidimensional-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














What you showed us is a JSON string (giving a JS object after parsing), not an array.



So d[0].phoneNumbers will not work and d.phoneNumbers will work and will give you an array.



And because it will give you an array, d.phoneNumbers.value will not work, and d.phoneNumbers[0].value will.






share|improve this answer





















  • 1





    test is the original string, the OP has given the name d to the object formed by parsing it

    – Robin Zigmond
    Jan 2 at 16:33











  • Corrected, thanks

    – iArcadia
    Jan 2 at 16:35
















1














What you showed us is a JSON string (giving a JS object after parsing), not an array.



So d[0].phoneNumbers will not work and d.phoneNumbers will work and will give you an array.



And because it will give you an array, d.phoneNumbers.value will not work, and d.phoneNumbers[0].value will.






share|improve this answer





















  • 1





    test is the original string, the OP has given the name d to the object formed by parsing it

    – Robin Zigmond
    Jan 2 at 16:33











  • Corrected, thanks

    – iArcadia
    Jan 2 at 16:35














1












1








1







What you showed us is a JSON string (giving a JS object after parsing), not an array.



So d[0].phoneNumbers will not work and d.phoneNumbers will work and will give you an array.



And because it will give you an array, d.phoneNumbers.value will not work, and d.phoneNumbers[0].value will.






share|improve this answer















What you showed us is a JSON string (giving a JS object after parsing), not an array.



So d[0].phoneNumbers will not work and d.phoneNumbers will work and will give you an array.



And because it will give you an array, d.phoneNumbers.value will not work, and d.phoneNumbers[0].value will.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 16:34

























answered Jan 2 at 16:16









iArcadiaiArcadia

1,151619




1,151619








  • 1





    test is the original string, the OP has given the name d to the object formed by parsing it

    – Robin Zigmond
    Jan 2 at 16:33











  • Corrected, thanks

    – iArcadia
    Jan 2 at 16:35














  • 1





    test is the original string, the OP has given the name d to the object formed by parsing it

    – Robin Zigmond
    Jan 2 at 16:33











  • Corrected, thanks

    – iArcadia
    Jan 2 at 16:35








1




1





test is the original string, the OP has given the name d to the object formed by parsing it

– Robin Zigmond
Jan 2 at 16:33





test is the original string, the OP has given the name d to the object formed by parsing it

– Robin Zigmond
Jan 2 at 16:33













Corrected, thanks

– iArcadia
Jan 2 at 16:35





Corrected, thanks

– iArcadia
Jan 2 at 16:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009583%2fgetting-values-from-json-multidimensional-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The term 'EXEC' is not recognized as the name of a cmdlet Powershell

NPM command prompt closes immediately [closed]

Error binding properties and functions in emscripten