SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict dr_dumb99's Avatar
    Join Date
    Sep 2004
    Location
    Pakistan
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How can I get value of Json in jQuery

    I have following Json string (returned from server) :
    Code:
    [{"rurl":"Asia.com","status":1,"recordType":0}, {"rurl":"Africa.com","status":1,"recordType":0}]
    Iam using following code to get JSON values but Iam getting "UNDEFINED" value. I want to access "rurl" => "Africa.com"
    Code:
    success: function(data) {
                                           var encoded = jQuery.toJSON(data);
                                           alert(jQuery.evalJSON(encoded).rurl);
    Can some one guide me, what and where Iam doing wrong. And how can rectify it.

    Thanks in advance

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have to learn to debug your own code.

    There is no "toJSON" or "evalJSON", just parseJSON.

    http://api.jquery.com/?ns0=1&s=JSON&go=

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Make sure you tell jQuery you're expecting a JSON response:

    Code:
    $.post(url, params, function(data) {
        console.info(data); // this will be a javascript object
    }, "json");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •