How to access JSON Object name/value?Is it possible to use a string with multiple words as json key?Remove Count Attribute in json dataI have a string that I want to get the JSON value fromHow to return individual value from a json response in different URLbest way to get the key of a key/value javascript objectHow to get particular json key value from Response ObjectJs Object - Getting the ValueHow to access object using index notationHow to read JSON using javascript?Echo-ing back data from php to ajax and print itHow can I upload files asynchronously?How do I check if an element is hidden in jQuery?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How do I redirect to another webpage?How to check whether a checkbox is checked in jQuery?Why does Google prepend while(1); to their JSON responses?How do I return the response from an asynchronous call?
Satellite in orbit in front of and behind the Moon
Is it better to have a 10 year gap or a bad reference?
Do gauntlets count as armor?
How far off did Apollo 11 land?
Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?
What does this chess proverb mean?
I have a domain, static IP and many devices I'd like to access outside my house. How to route them?
How can I show that the speed of light in vacuum is the same in all reference frames?
How to create complicated tables (multiple nested columns and rows)
How much did all the space agencies spent on rockets launching and space exploration? What are the benefits for me and you?
What is this light passenger prop airplane which crash landed in East Kalimantan, Borneo in 1983?
Conditional statement in a function for PS1 are not re-evalutated
Why didn't NASA launch communications relay satellites for the Apollo missions?
Manager is asking me to eat breakfast from now on
Do we have to introduce the character's name before using their names in a dialogue tag?
Install suspension forks on non-suspension bike
Why is the forgetful functor representable?
I want light controlled by one switch, not two
Is art a form of communication?
Why does Plot only sometimes use different colors for each curve
What is the origin of "Wonder begets wisdom?"
Nilpotent elements of Lie algebra and unipotent groups
What does "play in traffic" mean?
Can two waves interfere head on?
How to access JSON Object name/value?
Is it possible to use a string with multiple words as json key?Remove Count Attribute in json dataI have a string that I want to get the JSON value fromHow to return individual value from a json response in different URLbest way to get the key of a key/value javascript objectHow to get particular json key value from Response ObjectJs Object - Getting the ValueHow to access object using index notationHow to read JSON using javascript?Echo-ing back data from php to ajax and print itHow can I upload files asynchronously?How do I check if an element is hidden in jQuery?How do I format a Microsoft JSON date?Can comments be used in JSON?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How do I redirect to another webpage?How to check whether a checkbox is checked in jQuery?Why does Google prepend while(1); to their JSON responses?How do I return the response from an asynchronous call?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
function (data)
//add values based on activity type
//data = JSON.parse(data);
//alert(abc.Phone1);
alert(data.myName)
alert(data.toString());
if (activityType == "Phone")
return;
,
As you can see this callback function of $.ajax
taking JSON
data from controller.
For example:
["name":"myName" ,"address": "myAddress" ]
In this case my first alert giving me undefined and second/third alert popup comes up with:
["name":"myName" ,"address": "myAddress" ]
How can I access value by name so that my first alert filled out with myName
which is value of name
?
jquery ajax json asp.net-mvc-3
add a comment |
function (data)
//add values based on activity type
//data = JSON.parse(data);
//alert(abc.Phone1);
alert(data.myName)
alert(data.toString());
if (activityType == "Phone")
return;
,
As you can see this callback function of $.ajax
taking JSON
data from controller.
For example:
["name":"myName" ,"address": "myAddress" ]
In this case my first alert giving me undefined and second/third alert popup comes up with:
["name":"myName" ,"address": "myAddress" ]
How can I access value by name so that my first alert filled out with myName
which is value of name
?
jquery ajax json asp.net-mvc-3
add a comment |
function (data)
//add values based on activity type
//data = JSON.parse(data);
//alert(abc.Phone1);
alert(data.myName)
alert(data.toString());
if (activityType == "Phone")
return;
,
As you can see this callback function of $.ajax
taking JSON
data from controller.
For example:
["name":"myName" ,"address": "myAddress" ]
In this case my first alert giving me undefined and second/third alert popup comes up with:
["name":"myName" ,"address": "myAddress" ]
How can I access value by name so that my first alert filled out with myName
which is value of name
?
jquery ajax json asp.net-mvc-3
function (data)
//add values based on activity type
//data = JSON.parse(data);
//alert(abc.Phone1);
alert(data.myName)
alert(data.toString());
if (activityType == "Phone")
return;
,
As you can see this callback function of $.ajax
taking JSON
data from controller.
For example:
["name":"myName" ,"address": "myAddress" ]
In this case my first alert giving me undefined and second/third alert popup comes up with:
["name":"myName" ,"address": "myAddress" ]
How can I access value by name so that my first alert filled out with myName
which is value of name
?
jquery ajax json asp.net-mvc-3
jquery ajax json asp.net-mvc-3
edited Jul 7 '15 at 7:41
dspacejs
1,1722 gold badges14 silver badges23 bronze badges
1,1722 gold badges14 silver badges23 bronze badges
asked Jun 5 '12 at 10:05
RollerCostaRollerCosta
2,7476 gold badges41 silver badges65 bronze badges
2,7476 gold badges41 silver badges65 bronze badges
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
In stead of parsing JSON you can do like followng:
$.ajax(
..
dataType: 'json' // using json, jquery will make parse for you
);
To access a property of your JSON do following:
data[0].name;
data[0].address;
Why you need data[0]
because data is an array, so to its content retrieve you need data[0]
(first element), which gives you an object "name":"myName" ,"address": "myAddress"
.
And to access property of an object rule is:
Object.property
or sometimes
Object["property"] // in some case
So you need
data[0].name
and so on to get what you want.
If you not
set dataType: json
then you need to parse them using $.parseJSON()
and to retrieve data like above.
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
coulddata[0].[0]
work, to accessname
? Looking at it like an array.
– Malcolm Salvador
Mar 8 '17 at 0:15
add a comment |
The JSON you are receiving is in string. You have to convert it into JSON object
You have commented the most important line of code
data = JSON.parse(data);
Or if you are using jQuery
data = $.parseJSON(data)
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
add a comment |
If you response is like 'customer':'first_name':'John','last_name':'Cena'
var d = JSON.parse(response);
alert(d.customer.first_name); // contains "John"
Thanks,
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
add a comment |
You should do
alert(data[0].name); //Take the property name of the first array
and not
alert(data.myName)
jQuery should be able to sniff the dataType for you even if you don't set it so no need for JSON.parse.
fiddle here
http://jsfiddle.net/H2yN6/
add a comment |
Try this code..
function (data)
var json = jQuery.parseJSON(data);
alert( json.name );
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
add a comment |
I think you should mention dataType: 'json'
in ajax config and to access that value:
data[0].name
add a comment |
You might want to try this approach:
var str =" "name" : "user"";
var jsonData = JSON.parse(str);
console.log(jsonData.name)
//Array Object
str ="[ "name" : "user", "name" : "user2"]";
jsonData = JSON.parse(str);
console.log(jsonData[0].name)
add a comment |
Here is a friendly piece of advice. Use something like Chrome Developer Tools or Firebug for Firefox to inspect your Ajax calls and results.
You may also want to invest some time in understanding a helper library like Underscore, which complements jQuery and gives you 60+ useful functions for manipulating data objects with JavaScript.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10895306%2fhow-to-access-json-object-name-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
In stead of parsing JSON you can do like followng:
$.ajax(
..
dataType: 'json' // using json, jquery will make parse for you
);
To access a property of your JSON do following:
data[0].name;
data[0].address;
Why you need data[0]
because data is an array, so to its content retrieve you need data[0]
(first element), which gives you an object "name":"myName" ,"address": "myAddress"
.
And to access property of an object rule is:
Object.property
or sometimes
Object["property"] // in some case
So you need
data[0].name
and so on to get what you want.
If you not
set dataType: json
then you need to parse them using $.parseJSON()
and to retrieve data like above.
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
coulddata[0].[0]
work, to accessname
? Looking at it like an array.
– Malcolm Salvador
Mar 8 '17 at 0:15
add a comment |
In stead of parsing JSON you can do like followng:
$.ajax(
..
dataType: 'json' // using json, jquery will make parse for you
);
To access a property of your JSON do following:
data[0].name;
data[0].address;
Why you need data[0]
because data is an array, so to its content retrieve you need data[0]
(first element), which gives you an object "name":"myName" ,"address": "myAddress"
.
And to access property of an object rule is:
Object.property
or sometimes
Object["property"] // in some case
So you need
data[0].name
and so on to get what you want.
If you not
set dataType: json
then you need to parse them using $.parseJSON()
and to retrieve data like above.
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
coulddata[0].[0]
work, to accessname
? Looking at it like an array.
– Malcolm Salvador
Mar 8 '17 at 0:15
add a comment |
In stead of parsing JSON you can do like followng:
$.ajax(
..
dataType: 'json' // using json, jquery will make parse for you
);
To access a property of your JSON do following:
data[0].name;
data[0].address;
Why you need data[0]
because data is an array, so to its content retrieve you need data[0]
(first element), which gives you an object "name":"myName" ,"address": "myAddress"
.
And to access property of an object rule is:
Object.property
or sometimes
Object["property"] // in some case
So you need
data[0].name
and so on to get what you want.
If you not
set dataType: json
then you need to parse them using $.parseJSON()
and to retrieve data like above.
In stead of parsing JSON you can do like followng:
$.ajax(
..
dataType: 'json' // using json, jquery will make parse for you
);
To access a property of your JSON do following:
data[0].name;
data[0].address;
Why you need data[0]
because data is an array, so to its content retrieve you need data[0]
(first element), which gives you an object "name":"myName" ,"address": "myAddress"
.
And to access property of an object rule is:
Object.property
or sometimes
Object["property"] // in some case
So you need
data[0].name
and so on to get what you want.
If you not
set dataType: json
then you need to parse them using $.parseJSON()
and to retrieve data like above.
edited Jun 5 '12 at 10:22
answered Jun 5 '12 at 10:09
thecodeparadoxthecodeparadox
72.9k18 gold badges125 silver badges158 bronze badges
72.9k18 gold badges125 silver badges158 bronze badges
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
coulddata[0].[0]
work, to accessname
? Looking at it like an array.
– Malcolm Salvador
Mar 8 '17 at 0:15
add a comment |
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
coulddata[0].[0]
work, to accessname
? Looking at it like an array.
– Malcolm Salvador
Mar 8 '17 at 0:15
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
maps.googleapis.com/maps/api/geocode/… from this url how should get "formatted_address" field value in a variable? success : function(data) address = data['formatted_address']; throws an error
– user3816325
Apr 14 '16 at 9:50
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:
if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
is there a more optimized way to do so? if I have a json list of more than 20 names and i need to display their value, but I don't know if which one of them will be returned in the json, it could be ony one or 3 or 10 or all 20 of them, should I repeat the same for each one of them, for example:
if data[0].name : console.log(data[0].name); if data[0].adress : console.log(data[0].adress); ..
– Armance
Nov 30 '16 at 10:09
could
data[0].[0]
work, to access name
? Looking at it like an array.– Malcolm Salvador
Mar 8 '17 at 0:15
could
data[0].[0]
work, to access name
? Looking at it like an array.– Malcolm Salvador
Mar 8 '17 at 0:15
add a comment |
The JSON you are receiving is in string. You have to convert it into JSON object
You have commented the most important line of code
data = JSON.parse(data);
Or if you are using jQuery
data = $.parseJSON(data)
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
add a comment |
The JSON you are receiving is in string. You have to convert it into JSON object
You have commented the most important line of code
data = JSON.parse(data);
Or if you are using jQuery
data = $.parseJSON(data)
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
add a comment |
The JSON you are receiving is in string. You have to convert it into JSON object
You have commented the most important line of code
data = JSON.parse(data);
Or if you are using jQuery
data = $.parseJSON(data)
The JSON you are receiving is in string. You have to convert it into JSON object
You have commented the most important line of code
data = JSON.parse(data);
Or if you are using jQuery
data = $.parseJSON(data)
answered Jun 5 '12 at 10:08
Obi-Wan SpockObi-Wan Spock
6,3145 gold badges30 silver badges52 bronze badges
6,3145 gold badges30 silver badges52 bronze badges
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
add a comment |
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
even on uncommenting the line i receive undefined
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
data = $.parseJSON(data) for that i received an error
– RollerCosta
Jun 5 '12 at 10:14
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
That is because your JSON is an array. Try data[0].name instead of data.name. And make sure you access property not value i.e. data[0].name (property) instead of what you are doing in your question data.myName(which is value)
– Obi-Wan Spock
Jun 5 '12 at 10:18
add a comment |
If you response is like 'customer':'first_name':'John','last_name':'Cena'
var d = JSON.parse(response);
alert(d.customer.first_name); // contains "John"
Thanks,
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
add a comment |
If you response is like 'customer':'first_name':'John','last_name':'Cena'
var d = JSON.parse(response);
alert(d.customer.first_name); // contains "John"
Thanks,
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
add a comment |
If you response is like 'customer':'first_name':'John','last_name':'Cena'
var d = JSON.parse(response);
alert(d.customer.first_name); // contains "John"
Thanks,
If you response is like 'customer':'first_name':'John','last_name':'Cena'
var d = JSON.parse(response);
alert(d.customer.first_name); // contains "John"
Thanks,
answered Nov 27 '14 at 15:19
Mahendran SakkaraiMahendran Sakkarai
5,9973 gold badges31 silver badges62 bronze badges
5,9973 gold badges31 silver badges62 bronze badges
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
add a comment |
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
Hi, If I wanted to extract 'customer' how would I do that where customer is the actual thing I want. In my case I want to extract aboutme.jpg that below as a string b'"_id":"2","_rev":"5-760e627e77645e960c5cc40ea6cf03a2","_attachments":"aboutme.jpg":"content_type":"image/jpeg","revpos":3,"digest":"md5-mG5uU4IRGuY/f9PbZ8AIbQ==","length":98831,"stub":truen'
– Andrew Irwin
Nov 26 '16 at 22:11
1
1
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
stackoverflow.com/a/16068794/3049065 I think that answer will help you.
– Mahendran Sakkarai
Nov 26 '16 at 22:27
1
1
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
stackoverflow.com/a/28670472/3049065 this one too..
– Mahendran Sakkarai
Nov 26 '16 at 22:28
add a comment |
You should do
alert(data[0].name); //Take the property name of the first array
and not
alert(data.myName)
jQuery should be able to sniff the dataType for you even if you don't set it so no need for JSON.parse.
fiddle here
http://jsfiddle.net/H2yN6/
add a comment |
You should do
alert(data[0].name); //Take the property name of the first array
and not
alert(data.myName)
jQuery should be able to sniff the dataType for you even if you don't set it so no need for JSON.parse.
fiddle here
http://jsfiddle.net/H2yN6/
add a comment |
You should do
alert(data[0].name); //Take the property name of the first array
and not
alert(data.myName)
jQuery should be able to sniff the dataType for you even if you don't set it so no need for JSON.parse.
fiddle here
http://jsfiddle.net/H2yN6/
You should do
alert(data[0].name); //Take the property name of the first array
and not
alert(data.myName)
jQuery should be able to sniff the dataType for you even if you don't set it so no need for JSON.parse.
fiddle here
http://jsfiddle.net/H2yN6/
answered Jun 5 '12 at 10:09
Nicola PeluchettiNicola Peluchetti
63.8k27 gold badges120 silver badges171 bronze badges
63.8k27 gold badges120 silver badges171 bronze badges
add a comment |
add a comment |
Try this code..
function (data)
var json = jQuery.parseJSON(data);
alert( json.name );
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
add a comment |
Try this code..
function (data)
var json = jQuery.parseJSON(data);
alert( json.name );
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
add a comment |
Try this code..
function (data)
var json = jQuery.parseJSON(data);
alert( json.name );
Try this code..
function (data)
var json = jQuery.parseJSON(data);
alert( json.name );
answered Jun 5 '12 at 10:09
Kabilan SKabilan S
9383 gold badges13 silver badges28 bronze badges
9383 gold badges13 silver badges28 bronze badges
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
add a comment |
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
var json = jQuery.parseJSON(data); not working for me
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
i tried it before and getting an error Microsoft JScript runtime error: Object doesn't support property or method 'parseJSON'
– RollerCosta
Jun 5 '12 at 10:11
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
are you not using Jquery ?
– Kabilan S
Jun 5 '12 at 10:13
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
yes i am using it
– RollerCosta
Jun 5 '12 at 10:32
add a comment |
I think you should mention dataType: 'json'
in ajax config and to access that value:
data[0].name
add a comment |
I think you should mention dataType: 'json'
in ajax config and to access that value:
data[0].name
add a comment |
I think you should mention dataType: 'json'
in ajax config and to access that value:
data[0].name
I think you should mention dataType: 'json'
in ajax config and to access that value:
data[0].name
answered Jun 5 '12 at 10:15
The System RestartThe System Restart
2,61313 silver badges26 bronze badges
2,61313 silver badges26 bronze badges
add a comment |
add a comment |
You might want to try this approach:
var str =" "name" : "user"";
var jsonData = JSON.parse(str);
console.log(jsonData.name)
//Array Object
str ="[ "name" : "user", "name" : "user2"]";
jsonData = JSON.parse(str);
console.log(jsonData[0].name)
add a comment |
You might want to try this approach:
var str =" "name" : "user"";
var jsonData = JSON.parse(str);
console.log(jsonData.name)
//Array Object
str ="[ "name" : "user", "name" : "user2"]";
jsonData = JSON.parse(str);
console.log(jsonData[0].name)
add a comment |
You might want to try this approach:
var str =" "name" : "user"";
var jsonData = JSON.parse(str);
console.log(jsonData.name)
//Array Object
str ="[ "name" : "user", "name" : "user2"]";
jsonData = JSON.parse(str);
console.log(jsonData[0].name)
You might want to try this approach:
var str =" "name" : "user"";
var jsonData = JSON.parse(str);
console.log(jsonData.name)
//Array Object
str ="[ "name" : "user", "name" : "user2"]";
jsonData = JSON.parse(str);
console.log(jsonData[0].name)
edited Mar 26 at 12:33
baduker
1,2224 gold badges11 silver badges21 bronze badges
1,2224 gold badges11 silver badges21 bronze badges
answered Mar 26 at 11:57
Mansuri NurulhudaMansuri Nurulhuda
211 bronze badge
211 bronze badge
add a comment |
add a comment |
Here is a friendly piece of advice. Use something like Chrome Developer Tools or Firebug for Firefox to inspect your Ajax calls and results.
You may also want to invest some time in understanding a helper library like Underscore, which complements jQuery and gives you 60+ useful functions for manipulating data objects with JavaScript.
add a comment |
Here is a friendly piece of advice. Use something like Chrome Developer Tools or Firebug for Firefox to inspect your Ajax calls and results.
You may also want to invest some time in understanding a helper library like Underscore, which complements jQuery and gives you 60+ useful functions for manipulating data objects with JavaScript.
add a comment |
Here is a friendly piece of advice. Use something like Chrome Developer Tools or Firebug for Firefox to inspect your Ajax calls and results.
You may also want to invest some time in understanding a helper library like Underscore, which complements jQuery and gives you 60+ useful functions for manipulating data objects with JavaScript.
Here is a friendly piece of advice. Use something like Chrome Developer Tools or Firebug for Firefox to inspect your Ajax calls and results.
You may also want to invest some time in understanding a helper library like Underscore, which complements jQuery and gives you 60+ useful functions for manipulating data objects with JavaScript.
answered Jun 5 '12 at 10:27
ButifarraButifarra
9746 silver badges12 bronze badges
9746 silver badges12 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10895306%2fhow-to-access-json-object-name-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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