1

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.

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

7 Comments

I'm also using firefox, how are you viewing the string after the serialization? (i fixed the typo, thanks)
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???
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.
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??
The problem was that i was filling the arrays in with an ajax call (that hadnt returned yet).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.