1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    58
    Vote Rating
    -3
    Shri_SenchaDev can only hope to improve

      0  

    Default get value from the json list

    get value from the json list


    Hi all,
    I have a json object and in that object contain the list of values.
    Suppose code is ,

    success: function (response) {
    var obj = JSON.stringify(response);
    alert(obj);


    if function success it return following result-

    {"GetAllResult":[{"ID":"5","Name":"Lenny"}]}

    Now, i want to get the perticular value like the 'Name' from above list.
    So how i can get this?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,541
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    loop through the array with a for loop. Simple JavaScript
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi,

    you can try this

    alert(obj.GetAllResult.Name);
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  4. #4
    Sencha User
    Join Date
    Mar 2009
    Location
    Fort Worth, TX
    Posts
    65
    Vote Rating
    -36
    jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts jemptymethod is infamous around these parts

      0  

    Default


    Quote Originally Posted by sword-it View Post
    Hi,

    you can try this

    alert(obj.GetAllResult.Name);
    Except that it appears that the OP has called JSON.stringify on what very well may already be a string, if their 'success' function is that of an Ext.Ajax.request anyway, in which case they first need to convert the JSON string to an object.

  5. #5
    Sencha User
    Join Date
    Aug 2012
    Posts
    58
    Vote Rating
    -3
    Shri_SenchaDev can only hope to improve

      0  

    Default


    hi mitchellsimoens ,

    i tried this
    alert(obj.GetAllResult.Name); but not getting result. getting error of Name undefined.

    You say that use for loop , can u give the code of the for loop?

  6. #6
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi,

    you can use following code:

    Code:
    success: function (response) {
                    var data = Ext.util.JSON.decode(response.responseText);
                    alert(data.GetAllResult[0].Name);
                  }
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  7. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,541
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by Shri_SenchaDev View Post
    hi mitchellsimoens ,

    i tried this
    alert(obj.GetAllResult.Name); but not getting result. getting error of Name undefined.

    You say that use for loop , can u give the code of the for loop?
    That's because GetAllResult is an array
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  8. #8
    Sencha User
    Join Date
    Aug 2012
    Posts
    58
    Vote Rating
    -3
    Shri_SenchaDev can only hope to improve

      0  

    Default


    success: function (response) { var data = Ext.util.JSON.decode(response.responseText); alert(data.GetAllResult[0].Name); }Getting an error - Object [object Object] has no method 'decode'

  9. #9
    Sencha User
    Join Date
    Aug 2012
    Posts
    58
    Vote Rating
    -3
    Shri_SenchaDev can only hope to improve

      0  

    Default


    hi mitchellsimoens,
    give the code for looping json and get element from it.