Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2009, 03:09 AM   PM User | #1
heals1ic
New Coder

 
Join Date: Sep 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
heals1ic is an unknown quantity at this point
jquery decode json object with double quoted keys

I have a script that outputs a json string via json_encode in PHP. The json string consists of

PHP Code:
[{"custId":"2","custName":"John Inc"}] 
The PHP script is initiated using

Code:
$.getJSON("customer.php", function(data){alert(data + '  ' + data.custName);});
The response is -

Code:
[object Object] undefined
Javascript recognises 'data' as an object but I cannot seem to reference the information using json dotted notation.
heals1ic is offline   Reply With Quote
Old 08-05-2009, 03:14 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
try using
Code:
alert(data.toSource());
in firefox, and see what data actually is.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 08-05-2009, 04:24 AM   PM User | #3
heals1ic
New Coder

 
Join Date: Sep 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
heals1ic is an unknown quantity at this point
Work it out that I had braces surrounding my json string therefore it was being interpreted as array(object).

Fixed it with data[0].custName

Cheers
heals1ic is offline   Reply With Quote
Reply

Bookmarks

Tags
getjson, json, json-encode

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:58 AM.


Advertisement
Log in to turn off these ads.