JsonConvert.DeserializeObject and “d” wrapper in WCF

后端 未结 7 504
梦谈多话
梦谈多话 2020-12-21 08:53

By default WCF service wrap JSON response in \"d\" wrapper and there I found a problem with parsing it.

If I parse with JsonConvert.DeserializeObject(respons

7条回答
  •  眼角桃花
    2020-12-21 09:19

    Now I got rid of "d" wrapper with Regex.Replace and fix JSON response with proper structure

    {\"Guid\":\"a0b70d2f-7fe4-4aa2-b600-066201eab82d\",\"Name\":\"Thelma\"}
    {\"Guid\":\"d56d4d4f-6029-40df-a23b-de27617a1e43\",\"Name\":\"Lousie\"}\"}
    

    I also make a class with Guid and Name, defined as string in it.

    Then try to deserialize it with

    List o = JsonConvert.DeserializeObject>(response);
    

    But i get an error

    Expected a JsonObjectContract or JsonDictionaryContract for type 'System.Collections.Generic.List`1[mynamespace.myStruct]', got 'Newtonsoft.Json.Serialization.JsonArrayContract'.
    

    Where is the trick?

提交回复
热议问题