内容如下:
{"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; }
}
为什么有这么多转义符?
\"Url\":\"http://basetexture.s.vidahouse.com/FjsXszmaL83kAmYcPP5SxuqzqYNe\",\"Hash\":\"9757779f3df625fb7a6d6388188ee97d\"
说明是字符串值不是对象.肯定是你定义的实体结构不对
你把json字符串复制一下.然后在vs->编辑->选择性粘贴->粘贴json为类.就能生成对应的实体
你还需要一个
class X { public ProductModel data {get;set;}}
T model = JsonConvert.SerializeObject(strJson);
你的json内容是错误的,
可以把内容拷贝到以下网站验证一下就知道了
http://json.cn/