Deserialization problem with DataContractJsonSerializer

前端 未结 2 1760
失恋的感觉
失恋的感觉 2020-12-01 12:34

I\'ve got the following piece of JSON:

[{
    \"name\": \"numToRetrieve\",
    \"value\": \"3\",
    \"label\": \"Number of items to retrieve:\",
    \"items         


        
相关标签:
2条回答
  • 2020-12-01 12:49

    IMHO there is no way to deserialize the JSON string you provided into a .NET class using DataContractJsonSerializer.

    The problem comes from the way DataContractJsonSerializer serializes dictionaries. You could use an alternative serializer such as Json.NET (which I strongly recommend) or JavaScriptSerializer (I think it was deprecated in favor of DataContractJsonSerializer but it will work for your scenario).

    You can also read these rants.

    Documentation: Serializing Collections - Json.NET

    0 讨论(0)
  • 2020-12-01 13:08

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/071f73bb-e141-4a68-ae61-05635382934f

    Check this article out - it solved my problem almost perfectly. I had to change their object[] Type to a string, but i'm only using strings:string type Key/Value pairs, so no problems there.

    0 讨论(0)
提交回复
热议问题