首页 新闻 会员 周边

C#如何用Newtonsoft.Json将此json反序列化为对象,求答案。谢谢

0
悬赏园豆:15 [已关闭问题] 关闭于 2017-01-04 17:45

 内容如下:

{"data":{"id":9544,"productId":7090,"name":"15542","images":"http://itemicon.s.vidahouse.com/FoaD25wPNfb48EeORpejaRwt8jjJ","description":"婴儿床-儿童","style":{"style":6,"complexity":6,"metalness":3,"roughness":4,"size":6,"gender":5,"age":0},"components":[{"id":214400,"fromId":0,"name":"15542_Item000.uasset","model":"{\"Url\":\"http://mesh.s.vidahouse.com/FotCLJQ6sCnB_ERkX0Pb0sfxBEze\",\"Hash\":\"0800a422cbeb13221a0525a918273da7\"}","material":{"id":124537,"materialId":69095,"name":"Fabric_Texture15542","images":"http://textureicon.s.vidahouse.com/Fabric_Texture15542_9539","description":"","template":"Fabric_Texture","params":"","dna":{"style":-1,"complexity":-1,"metalness":-1,"roughness":-1,"size":-1,"gender":-1,"age":-1},"customAttributes":[{"name":"tBaseTexture","displayName":"BaseTexture","valueType":"DownloadFile","value":"{\"Url\":\"http://basetexture.s.vidahouse.com/FjsXszmaL83kAmYcPP5SxuqzqYNe\",\"Hash\":\"9757779f3df625fb7a6d6388188ee97d\"}"},{"name":"fRoughness","displayName":"Roughness","valueType":"Number","value":"0.65"},{"name":"fSpecular","displayName":"Specular","valueType":"Number","value":"0.2"}],"categoryId":455,"supplierId":982,"createdUtc":"2017-01-03T03:39:00Z","updatedUtc":"2017-01-03T03:39:00Z","latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null},"extraData":null,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2853994Z"}],"size":{"x":0.0,"y":0.0,"z":0.0},"functionType":null,"isSharedModel":false,"categoryId":0,"customAttributes":[{"name":"bPrice","displayName":"Price","valueType":"Number","value":"500"},{"name":"tTaobaoLink","displayName":"TaobaoLink","valueType":"Text","value":"https://www.taobao.com/"},{"name":"cListable","displayName":"Listable","valueType":"DownloadFile","value":"true"}],"isVirtualProduct":false,"ownerId":379,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2756295Z","published":true,"latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null}}{"data":{"id":9544,"productId":7090,"name":"15542","images":"http://itemicon.s.vidahouse.com/FoaD25wPNfb48EeORpejaRwt8jjJ","description":"婴儿床-儿童","style":{"style":6,"complexity":6,"metalness":3,"roughness":4,"size":6,"gender":5,"age":0},"components":[{"id":214400,"fromId":0,"name":"15542_Item000.uasset","model":"{\"Url\":\"http://mesh.s.vidahouse.com/FotCLJQ6sCnB_ERkX0Pb0sfxBEze\",\"Hash\":\"0800a422cbeb13221a0525a918273da7\"}","material":{"id":124537,"materialId":69095,"name":"Fabric_Texture15542","images":"http://textureicon.s.vidahouse.com/Fabric_Texture15542_9539","description":"","template":"Fabric_Texture","params":"","dna":{"style":-1,"complexity":-1,"metalness":-1,"roughness":-1,"size":-1,"gender":-1,"age":-1},"customAttributes":[{"name":"tBaseTexture","displayName":"BaseTexture","valueType":"DownloadFile","value":"{\"Url\":\"http://basetexture.s.vidahouse.com/FjsXszmaL83kAmYcPP5SxuqzqYNe\",\"Hash\":\"9757779f3df625fb7a6d6388188ee97d\"}"},{"name":"fRoughness","displayName":"Roughness","valueType":"Number","value":"0.65"},{"name":"fSpecular","displayName":"Specular","valueType":"Number","value":"0.2"}],"categoryId":455,"supplierId":982,"createdUtc":"2017-01-03T03:39:00Z","updatedUtc":"2017-01-03T03:39:00Z","latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null},"extraData":null,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2853994Z"}],"size":{"x":0.0,"y":0.0,"z":0.0},"functionType":null,"isSharedModel":false,"categoryId":0,"customAttributes":[{"name":"bPrice","displayName":"Price","valueType":"Number","value":"500"},{"name":"tTaobaoLink","displayName":"TaobaoLink","valueType":"Text","value":"https://www.taobao.com/"},{"name":"cListable","displayName":"Listable","valueType":"DownloadFile","value":"true"}],"isVirtualProduct":false,"ownerId":379,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2756295Z","published":true,"latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null}}{"data":{"id":9544,"productId":7090,"name":"15542","images":"http://itemicon.s.vidahouse.com/FoaD25wPNfb48EeORpejaRwt8jjJ","description":"婴儿床-儿童","style":{"style":6,"complexity":6,"metalness":3,"roughness":4,"size":6,"gender":5,"age":0},"components":[{"id":214400,"fromId":0,"name":"15542_Item000.uasset","model":"{\"Url\":\"http://mesh.s.vidahouse.com/FotCLJQ6sCnB_ERkX0Pb0sfxBEze\",\"Hash\":\"0800a422cbeb13221a0525a918273da7\"}","material":{"id":124537,"materialId":69095,"name":"Fabric_Texture15542","images":"http://textureicon.s.vidahouse.com/Fabric_Texture15542_9539","description":"","template":"Fabric_Texture","params":"","dna":{"style":-1,"complexity":-1,"metalness":-1,"roughness":-1,"size":-1,"gender":-1,"age":-1},"customAttributes":[{"name":"tBaseTexture","displayName":"BaseTexture","valueType":"DownloadFile","value":"{\"Url\":\"http://basetexture.s.vidahouse.com/FjsXszmaL83kAmYcPP5SxuqzqYNe\",\"Hash\":\"9757779f3df625fb7a6d6388188ee97d\"}"},{"name":"fRoughness","displayName":"Roughness","valueType":"Number","value":"0.65"},{"name":"fSpecular","displayName":"Specular","valueType":"Number","value":"0.2"}],"categoryId":455,"supplierId":982,"createdUtc":"2017-01-03T03:39:00Z","updatedUtc":"2017-01-03T03:39:00Z","latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null},"extraData":null,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2853994Z"}],"size":{"x":0.0,"y":0.0,"z":0.0},"functionType":null,"isSharedModel":false,"categoryId":0,"customAttributes":[{"name":"bPrice","displayName":"Price","valueType":"Number","value":"500"},{"name":"tTaobaoLink","displayName":"TaobaoLink","valueType":"Text","value":"https://www.taobao.com/"},{"name":"cListable","displayName":"Listable","valueType":"DownloadFile","value":"true"}],"isVirtualProduct":false,"ownerId":379,"createdUtc":"2017-01-03T08:14:09Z","updatedUtc":"2017-01-03T09:24:12.2756295Z","published":true,"latest":true,"revision":1,"isLiked":false,"likedNumber":0,"isCollected":false,"collectedNumber":0,"extraData":null}}

 

下面是我定义的可用的实体,但Newtonsoft.Json;反序列化没有作用:

public class ProductModel
{
public int Id { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
public string Images { get; set; }
public string Description { get; set; }
public Style Style { get; set; }
public List<Components> Components { get; set; }
public Size Size { get; set; }
public string FunctionType { get; set; }
public bool IsSharedModel { get; set; }
public int CategoryId { get; set; }
public List<CustomAttributes> CustomAttributes { get; set; }
public bool IsVirtualProduct { get; set; }
public int OwnenId { get; set; }
public string CreatedUtc { get; set; }
public string UpdatedUtc { get; set; }
public bool Published { get; set; }
public bool Latest { get; set; }
public int Revision { get; set; }
public bool IsLiked { get; set; }
public int LikedNumber { get; set; }
public bool IsCollected { get; set; }
public int CollectedNumber { get; set; }
public string ExtraData { get; set; }

}
public class Style
{
public int style { get; set; }
public int Complexity { get; set; }
public int Metalness { get; set; }
public int Roughness { get; set; }
public int Size { get; set; }
public int Gender { get; set; }
public int Age { get; set; }

}

public class Components
{
public int Id { get; set; }
public int FromId { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public Material Material { get; set; }
public string ExtraData { get; set; }
public string CreatedUtc { get; set; }
public string UpdatedUtc { get; set; }
}

public class Material
{
public int Id { get; set; }
public int MaterialId { get; set; }
public string Name { get; set; }
public string Images { get; set; }
public string Description { get; set; }
public string Template { get; set; }
public string Params { get; set; }
public Dna Dna { get; set; }
public List<CustomAttributes> CustomAttributes { get; set; }
public int CategoryId { get; set; }
public int SupplierId { get; set; }
public string CreatedUtc { get; set; }
public string UpdatedUtc { get; set; }
public bool Latest { get; set; }
public int Revision { get; set; }
public bool IsLiked { get; set; }
public int LikedNumber { get; set; }
public bool IsCollected { get; set; }
public int CollectedNumber { get; set; }
public string ExtraData { get; set; }
}
public class Dna
{
public int Style { get; set; }
public int Complexity { get; set; }
public int Metalness { get; set; }
public int Roughness { get; set; }
public int Size { get; set; }
public int Gender { get; set; }
public int Age { get; set; }

}

public class Size
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
}
public class CustomAttributes
{
//public decimal bPrice { get; set; }
//public bool cListable { get; set; }
//public string tTaobaoLink { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }

public string ValueType { get; set; }

public string Value { get; set; }
}

renshen4322的主页 renshen4322 | 初学一级 | 园豆:5
提问于:2017-01-03 23:11
< >
分享
所有回答(6)
0

为什么有这么多转义符?

\"Url\":\"http://basetexture.s.vidahouse.com/FjsXszmaL83kAmYcPP5SxuqzqYNe\",\"Hash\":\"9757779f3df625fb7a6d6388188ee97d\"

Daniel Cai | 园豆:10424 (专家六级) | 2017-01-04 09:09
0

说明是字符串值不是对象.肯定是你定义的实体结构不对

你把json字符串复制一下.然后在vs->编辑->选择性粘贴->粘贴json为类.就能生成对应的实体

 

吴瑞祥 | 园豆:29449 (高人七级) | 2017-01-04 09:32
0

你还需要一个

class X { public ProductModel data {get;set;}}

长蘑菇星人 | 园豆:1832 (小虾三级) | 2017-01-04 09:36
0


T model = JsonConvert.SerializeObject(strJson);

大师兄丶 | 园豆:843 (小虾三级) | 2017-01-04 10:13
0

已经自己解决,同时提供个好的工具吧。 http://tool.chinaz.com/tools/json2entity.aspx json 生成实体

renshen4322 | 园豆:5 (初学一级) | 2017-01-04 10:28
0

你的json内容是错误的,

可以把内容拷贝到以下网站验证一下就知道了

http://json.cn/

chengeng | 园豆:294 (菜鸟二级) | 2017-01-04 17:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册