JsonConvert.DeserializeObject<> (string) returns null value for $id property

前端 未结 3 395
广开言路
广开言路 2020-11-29 13:14

I\'m downloading the JSON using System.Net.WebClient.DownloadString. I\'m getting a valid response:

{
\"FormDefinition\": [
    {
        \"$id\":\"4\",
             


        
3条回答
  •  心在旅途
    2020-11-29 13:53

    The problem is the $ sign, therefore a workaround would be:

    Remove the $ from the JsonProperty annotation.

    [JsonProperty ("id")]
    public string Id { get; set; }
    

    On your code, replace the special character $

    string response = "json as above";
    FormDefinitionList root = JsonConvert.DeserializeObject (response.Replace("$id","id"));
    

    Edited as @BrianRogers suggests

提交回复
热议问题