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;








67















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?










share|improve this question






























    67















    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?










    share|improve this question


























      67












      67








      67


      26






      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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






















          8 Answers
          8






          active

          oldest

          votes


















          99














          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.






          share|improve this answer

























          • 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












          • could data[0].[0] work, to access name? Looking at it like an array.

            – Malcolm Salvador
            Mar 8 '17 at 0:15


















          28














          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)





          share|improve this answer























          • 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



















          9














          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,






          share|improve this answer























          • 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


















          6














          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/






          share|improve this answer






























            4














            Try this code..



            function (data) 


            var json = jQuery.parseJSON(data);
            alert( json.name );








            share|improve this answer























            • 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


















            2














            I think you should mention dataType: 'json' in ajax config and to access that value:



            data[0].name





            share|improve this answer






























              1














              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)





              share|improve this answer
































                0














                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.






                share|improve this answer

























                  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%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









                  99














                  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.






                  share|improve this answer

























                  • 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












                  • could data[0].[0] work, to access name? Looking at it like an array.

                    – Malcolm Salvador
                    Mar 8 '17 at 0:15















                  99














                  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.






                  share|improve this answer

























                  • 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












                  • could data[0].[0] work, to access name? Looking at it like an array.

                    – Malcolm Salvador
                    Mar 8 '17 at 0:15













                  99












                  99








                  99







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  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












                  • could data[0].[0] work, to access name? 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












                  • 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
















                  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













                  28














                  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)





                  share|improve this answer























                  • 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
















                  28














                  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)





                  share|improve this answer























                  • 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














                  28












                  28








                  28







                  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)





                  share|improve this answer













                  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)






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  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


















                  • 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












                  9














                  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,






                  share|improve this answer























                  • 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















                  9














                  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,






                  share|improve this answer























                  • 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













                  9












                  9








                  9







                  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,






                  share|improve this answer













                  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,







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  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

















                  • 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











                  6














                  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/






                  share|improve this answer



























                    6














                    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/






                    share|improve this answer

























                      6












                      6








                      6







                      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/






                      share|improve this answer













                      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/







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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





















                          4














                          Try this code..



                          function (data) 


                          var json = jQuery.parseJSON(data);
                          alert( json.name );








                          share|improve this answer























                          • 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















                          4














                          Try this code..



                          function (data) 


                          var json = jQuery.parseJSON(data);
                          alert( json.name );








                          share|improve this answer























                          • 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













                          4












                          4








                          4







                          Try this code..



                          function (data) 


                          var json = jQuery.parseJSON(data);
                          alert( json.name );








                          share|improve this answer













                          Try this code..



                          function (data) 


                          var json = jQuery.parseJSON(data);
                          alert( json.name );









                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          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

















                          • 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











                          2














                          I think you should mention dataType: 'json' in ajax config and to access that value:



                          data[0].name





                          share|improve this answer



























                            2














                            I think you should mention dataType: 'json' in ajax config and to access that value:



                            data[0].name





                            share|improve this answer

























                              2












                              2








                              2







                              I think you should mention dataType: 'json' in ajax config and to access that value:



                              data[0].name





                              share|improve this answer













                              I think you should mention dataType: 'json' in ajax config and to access that value:



                              data[0].name






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jun 5 '12 at 10:15









                              The System RestartThe System Restart

                              2,61313 silver badges26 bronze badges




                              2,61313 silver badges26 bronze badges





















                                  1














                                  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)





                                  share|improve this answer





























                                    1














                                    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)





                                    share|improve this answer



























                                      1












                                      1








                                      1







                                      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)





                                      share|improve this answer















                                      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)






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      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





















                                          0














                                          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.






                                          share|improve this answer



























                                            0














                                            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.






                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              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.






                                              share|improve this answer













                                              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.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jun 5 '12 at 10:27









                                              ButifarraButifarra

                                              9746 silver badges12 bronze badges




                                              9746 silver badges12 bronze badges



























                                                  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%2f10895306%2fhow-to-access-json-object-name-value%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

                                                  Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                                  SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                                  은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현