问题描述
我已经通过POST发送的JSON简单的键/值列表返回到ASP.NET。例如:
{键1:值1,KEY2:VALUE2}
我不是要反序列化为强类型的.NET对象
我只需要一个普通的老式词典(字符串,字符串)或某些等效(哈希表,词典(字符串,对象),老派StringDictionary - 地狱,2-字符串的二维数组会为我工作。
我可以使用任何可用的ASP.NET 3.5,以及流行的Json.NET(这我已经使用了序列化的到客户端)。
显然,这些都不JSON库中有这样的额头,拍打着明显的能力开箱 - 他们是通过很强的合同完全专注于基于反射的反序列化
。任何想法?
限制:
- 我不想实现自己的JSON解析器
- 不能使用ASP.NET 4.0还没有
- 请问preFER远离年纪大了,德$ P $远pcated ASP.NET类JSON
Json.NET做到这一点...
JSON字符串= @{键1:值1,KEY2:值2};字典<字符串,字符串>值= JsonConvert.DeserializeObject<&字典LT;字符串,字符串>>(JSON);
更多的例子:<一href=\"http://james.newtonking.com/projects/json/help/index.html?topic=html/SerializingCollections.htm\">Serializing与Json.NET
集合I have a simple key/value list in JSON being sent back to ASP.NET via POST. Example:
{ "key1": "value1", "key2": "value2"}
I AM NOT TRYING TO DESERIALIZE INTO STRONGLY-TYPED .NET OBJECTS
I simply need a plain old Dictionary(Of String, String), or some equivalent (hash table, Dictionary(Of String, Object), old-school StringDictionary--hell, a 2-D array of strings would work for me.
I can use anything available in ASP.NET 3.5, as well as the popular Json.NET (which I'm already using for serialization to the client).
Apparently neither of these JSON libraries have this forehead-slapping obvious capability out of the box--they are totally focused on reflection-based deserialization via strong contracts.
Any ideas?
Limitations:
- I don't want to implement my own JSON parser
- Can't use ASP.NET 4.0 yet
- Would prefer to stay away from the older, deprecated ASP.NET class for JSON
Json.NET does this...
string json = @"{""key1"":""value1"",""key2"":""value2""}";
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
More examples: Serializing Collections with Json.NET
这篇关于我怎样才能JSON反序列化到一个简单的字典&LT;字符串,字符串&GT;在ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!