up vote 1 down vote favorite

I javascript I have an object that looks similar to:

var myObj = 
{
   prop1: 1,
   prop2: 2,
   prop3: ["a","b","c","d","e"],
   prop4: 4,
   prop5: ["f","g","h","i"]
}

It's an object containing a number of properties. Each property may or may not be an array.

  var serializedMyObj = JSON.stringify(myObj);

serializedMyObj is (found by viewing the results of the serialize function in firebug):

"{ "prop1":1, "prop2":2, "prop3":["a","b","c","d", "e"], "prop4":4, "prop5":["f","g","h","i"] }"

if I alert(serializedMyobj); it shows me:

{ "prop1":1, "prop2":2, "prop3":[], "prop4":4, "prop5":[] }

The real problem is when i pass this data into an Asp.Net PageMethod the server gets the same data I see when it's shown in the alert dialog, not in firebug. Somewhere it's losing the array values and only putting in [].

Does anyone know why this would happen or a way to fix it? It's probably something simple I'm overlooking.

link|flag

2 Answers

up vote 1 down vote accepted

I get the following (correct) output on firefox:

{"prop1":1,"prop2":2,"prop3":["a","b","c","d","e"],"prop4":4,"prop5":["f","g","h","i"]}

What browser are you using?

Also, I noticed that myObj was lowercase in JSON.stringify(myobj); - I assume that was just a typo?

link|flag
I'm also using firefox, how are you viewing the string after the serialization? (i fixed the typo, thanks) – John Boker Feb 19 at 22:23
Via alert(serializedMyObj); ... But firebug also agrees with this output. Is this your actual output, or just sanitized for SO? Maybe there are some invalid characters in there somewhere??? – Justin Ethier Feb 19 at 22:36
This isnt the actual data, the actual data is integer properties with Guid arrays, the Guids are represented as strings. I's all pretty simple stuff, there must be something overlooked by me. – John Boker Feb 19 at 22:53
You might want to carefully compare your data with the diagrams on json.org - perhaps you have an invalid character in there somewhere that is causing problems?? – Justin Ethier Feb 20 at 14:55
The problem was that i was filling the arrays in with an ajax call (that hadnt returned yet). – John Boker Feb 22 at 14:04
show 2 more comments
up vote 0 down vote

try jsonlint.com

link|flag

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.