繁体   English   中英

使用C#中的json.NET反序列化数组中的数组

[英]Deserialize array in array with json.NET in C#

我有一个以json格式提供的REST API。 json看起来像这样

[{"user":{"name":"foo","url":"bar"}}
  ,[{"product":{"name":"banana","price":"85"}},
  {"product":{"name":"peach","price":"66"}},
  {"product":{"name":"strawberry","price":"78"}}]]

如何使用json.NET进行传输?

我尝试了一些变化

public class Product
{
    [JsonProperty("Name")]
    public string name { get; set; }

    [JsonProperty("price")]
    public string Price { get; set; }
}

public class RootObject
{
    public Product product { get; set; }
}

但它不适用于Product p = JsonConvert.DeserializeObject<Product>(e.Result);

我如何申报这两个班级? 对不起,但是http://json2csharp.com/无效。

你想在JSON中用C#创建一个模型

public class User
{
   public string name { get; set; }
   public string url { get; set; }
   public List<Product> product { get; set; }

}

 public class Product
 {
    public string name { get; set; }
    public Decimal price { get; set; }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM