Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] JSON parsing... almost...



TLUG,

Sorry to be peppering the list with JSON/Javascript questions, but I'm very close to getting the whole circuit complete.

I've got my JSON going up to my PHP server, and I'm pretty sure it's coming back okay. But it seems that I'm not getting it to convert into a Javascript object.

Here's the code I'm using:

sendString = JSON.stringify(sendData);
  $.post('jsonhandler.php', {sendJSON: sendString}, checkResult, "json");
  function checkResult(json_data_received)
  {
    if (json_data_received)
    {
       dataObject = JSON.parse(json_data_received);
console.log ("This is one of the values in the JSON object: " + dataObject.variable )
    }
}

It gets down to the console log, so it's passing the "if(json_data_received)" test.

However, Firebug tells me "dataObject.variable is not set".

I thought that JSON.parse would structure a Javascript object, with nested values, so that if my JSON had {"variable" : "value"}, then the resulting object would have dataObject.varuable set to "value".

Where am I going wrong here?

Any advice would be much appreciated.

--
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links