質問

I have a dictionary that is serialised with JavaScriptSerializer from C#.

On the client side I have:

"{"dd049eda-e289-4ca2-8841-4908f94d5b65":"2","ab969ac2-320e-42e1-b759-038eb7f57178":"5"}"

How can I deserialise it so I can have a key-value pair array?

役に立ちましたか?

解決

Modern browsers support JSON.parse().

var arr_from_json = JSON.parse( json_string );

他のヒント

That will parse into an object with GUID keys.

To enumerate them, you can use:

var jsonString = '{"dd049eda-e289-4ca2-8841-4908f94d5b65":"2","ab969ac2-320e-42e1-b759-038eb7f57178":"5"}';
var map = JSON.parse(jsonString);
var keys = Object.keys(map);
for (var i =0; i < keys.length; i++)
{
    var key = keys[i];
    console.log(key, '=', map[key]);
}

This will output:

dd049eda-e289-4ca2-8841-4908f94d5b65 = 2
ab969ac2-320e-42e1-b759-038eb7f57178 = 5 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top