[jQuery] very simple JSON
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";
color:black;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
pre
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
span.EmailStyle17
{mso-style-type:personal;
font-family:Arial;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor=white lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I knew it must have been something simple—thanks,
all of you, for your help. (You know to be honest I feel like I’m pretty
darn good at my job, but adopting a new paradigm has been a hefty portion of
humility! I have much to learn…)<o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
color=black face="Times New Roman"><span style='font-size:12.0pt;color:windowtext'>
<hr size=3 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 color=black face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma;color:windowtext;font-weight:bold'>From:</span></font></b><font
size=2 color=black face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma;
color:windowtext'> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <b><span style='font-weight:bold'>On Behalf
Of </span></b>Christopher Jordan
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, February 06, 2007
4:27 PM
<b><span style='font-weight:bold'>To:</span></b> jQuery Discussion.
<b><span style='font-weight:bold'>Subject:</span></b> Re: [jQuery] very simple
JSON</span></font><font color=black><span style='color:windowtext'><o:p></o:p></span></font>
</div>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font>
<p class=MsoNormal><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>Paul, you forgot to eval the
JSON string. Andy (or anyone, really) can correct me if I'm wrong, but even
when using the $.get method you have to eval the JSON that gets returned.
For instance:
{"TRUCK":"INVALID", "ISVALID":false}
Is valid. But you need to have JavaScript evaluate the string to turn it into
an object (which can be thought of as a structure)
If you eval the above like this:
var MyData = eval("(" + response + ")");
You should then be able to say:
alert(MyData.Truck);
...and get the value "Invalid" as a result.
Does that help? I remember struggling with this stuff too, so feel free to
shout if this doesn't work or make sense.
Chris
</span></font>
Paul wrote: <o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u1:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="City"><u1:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"></u1:SmartTagType></u1:SmartTagType>I’m
sure this is something simple but I’m going nuts. I’m simply
trying to access JSON data that is being returned by an <st1:City u2:st="on"><st1:place u2:st="on"><st1:City
w:st="on"><st1:place w:st="on">ajax</st1:place></st1:City></st1:place></st1:City>
call. This is my first attempt to play with JSON, so here we go…<u1:p></u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u1:p> </u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=1 color=black face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'>$</span></font><font size=1
color=blue face=Consolas><span style='font-size:8.0pt;font-family:Consolas;
color:blue'>.</span></font><font size=1 face=Consolas><span style='font-size:
8.0pt;font-family:Consolas'>get(</span></font><font size=1 color="#006600"
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:#006600'>"cfc/scalehouse.cfc?method=validateTruckCode&truck_code="</span></font><font
size=1 face=Consolas><span style='font-size:8.0pt;font-family:Consolas'> </span></font><font
size=1 color=blue face=Consolas><span style='font-size:8.0pt;font-family:Consolas;
color:blue'>+</span></font><font size=1 face=Consolas><span style='font-size:
8.0pt;font-family:Consolas'> $(</span></font><font size=1 color="#006600"
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:#006600'>"input"</span></font><font
size=1 face=Consolas><span style='font-size:8.0pt;font-family:Consolas'>)</span></font><font
size=1 color=blue face=Consolas><span style='font-size:8.0pt;font-family:Consolas;
color:blue'>.val</span></font><font size=1 face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'>(),</span></font><o:p></o:p>
<u1:p></u1:p>
<p class=MsoNormal style='text-indent:.5in'><font size=1 color=blue
face=Consolas><span style='font-size:8.0pt;font-family:Consolas;color:blue'>function</span></font><font
size=1 face=Consolas><span style='font-size:8.0pt;font-family:Consolas'>(response){</span></font><o:p></o:p>
<u1:p></u1:p>
<p class=MsoNormal><font size=1 color=black face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'>
$('#content').html(response);
//THIS OUTPUTS
{"TRUCK":"INVALID","ISVALID":false}<u1:p></u1:p></span></font><o:p></o:p>
<p class=MsoNormal style='margin-left:.5in;text-indent:.5in'><font size=1
color="#0099ff" face=Consolas><span style='font-size:8.0pt;font-family:Consolas;
color:#0099FF'>alert</span></font><font size=1 face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'>(response</span></font><font
size=1 color=blue face=Consolas><span style='font-size:8.0pt;font-family:Consolas;
color:blue'>.</span></font><font size=1 face=Consolas><span style='font-size:
8.0pt;font-family:Consolas'>TRUCK);
//THIS ALERTS “undefined”—shouldn’t it alert
“INVALID”?</span></font><o:p></o:p>
<u1:p></u1:p>
<p class=MsoNormal><font size=1 color=black face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'><u1:p> </u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=1 color=black face=Consolas><span
style='font-size:8.0pt;font-family:Consolas'>
});</span></font><o:p></o:p>
<u1:p></u1:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u1:p> </u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Can you tell what I’ve done wrong?<u1:p></u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u1:p> </u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Thanks…<u1:p></u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u1:p> </u1:p></span></font><o:p></o:p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Paul<u1:p></u1:p></span></font><o:p></o:p>
<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre
style='text-align:center'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>
<hr size=4 width="90%" align=center>
</span></font></pre><pre><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>_______________________________________________<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>jQuery mailing list<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="mailto:discuss@jquery.com">discuss@jquery.com</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="http://jquery.com/discuss/">http://jquery.com/discuss/</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'> <o:p></o:p></span></font></pre>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'>
<o:p></o:p></span></font>
<pre><font size=2 color=black face="Courier New"><span style='font-size:10.0pt'>-- <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="http://www.cjordan.info">http://www.cjordan.info</a><o:p></o:p></span></font></pre></div>
</body>
</html>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/