首页新闻找找看学习计划

这个Json怎么反序列化...

0
[已解决问题] 解决于 2014-05-29 16:55
[
    {
        "r1": {
            "needs": [
                {
                    "need": "678", 
                    "score": 102, 
                    "category1": "保6", 
                    "category2": "男士产品"
                }, 
                {
                    "need": "紧紧致", 
                    "score": 23, 
                    "category1": "紧 老", 
                    "category2": "护 品"
                }
            ], 
            "skus": [
                {
                    "score": 126660.69, 
                    "category1": "护 产 品", 
                    "code": "G1305001", 
                    "category3": "抗 致", 
                    "category2": "乳液", 
                    "category4": "对 初老"
                }
            ]
        }
    }, 
    {
        "r2": {
            "needs": [
                {
                    "need": "脸 美妆", 
                    "score": 102, 
                    "category1": "脸 品", 
                    "category2": "彩 品"
                }, 
                {
                    "need": "脸部 桃花妆", 
                    "score": 23, 
                    "category1": "脸 品", 
                    "category2": "彩 品"
                }
            ], 
            "skus": [
                {
                    "score": 126.69, 
                    "category1": "彩品", 
                    "code": "G13201", 
                    "category3": "脸", 
                    "category2": "粉液", 
                    "category4": "雅韵妆"
                }
            ]
        }
    }, 
    {
        "r3": {
            "needs": [
                {
                    "need": "修受损", 
                    "score": 102, 
                    "category1": "修受损", 
                    "category2": "护产品"
                }, 
                {
                    "need": "修复日常受损;", 
                    "score": 23, 
                    "category1": "修复日常受损;莹润滋养;丝质顺滑", 
                    "category2": "护品"
                }
            ], 
            "skus": [
                {
                    "score": 120.69, 
                    "category1": "护发产品", 
                    "code": "G1268801", 
                    "category3": "修复日常受损;丝质顺滑", 
                    "category2": "精油", 
                    "category4": "修复日常受损;丝质顺滑"
                }
            ]
        }
    }, 
    {
        "r4": {
            "needs": [
                {
                    "need": "时尚系", 
                    "score": 102, 
                    "category1": "时色", 
                    "category2": "染品"
                }, 
                {
                    "need": "时系", 
                    "score": 23, 
                    "category1": "时色", 
                    "category2": "染品"
                }
            ], 
            "skus": [
                {
                    "score": 1.69, 
                    "category1": "产品", 
                    "code": "G134031", 
                    "category3": "发色", 
                    "category2": "", 
                    "category4": "色系"
                }
            ]
        }
    }
]

可以直接用Json.net来反序列化吗

菜菜菜菜鸟飞不动的主页 菜菜菜菜鸟飞不动 | 初学一级 | 园豆:81
提问于:2014-05-29 11:20
< >
分享
最佳答案
0
奖励园豆:5
Launcher | 高人七级 |园豆:45040 | 2014-05-29 16:25
其他回答(3)
0

可以解析成一个键值对数组

Key是一个字符串 Value类型照着格式定义就行.

吴瑞祥 | 园豆:28736 (高人七级) | 2014-05-29 11:24
0
public class Need
{
    public string need { get; set; }
    public int score { get; set; }
    public string category1 { get; set; }
    public string category2 { get; set; }
}

public class Sku
{
    public double score { get; set; }
    public string category1 { get; set; }
    public string code { get; set; }
    public string category3 { get; set; }
    public string category2 { get; set; }
    public string category4 { get; set; }
}

public class R1
{
    public List<Need> needs { get; set; }
    public List<Sku> skus { get; set; }
}

public class Need2
{
    public string need { get; set; }
    public int score { get; set; }
    public string category1 { get; set; }
    public string category2 { get; set; }
}

public class Sku2
{
    public double score { get; set; }
    public string category1 { get; set; }
    public string code { get; set; }
    public string category3 { get; set; }
    public string category2 { get; set; }
    public string category4 { get; set; }
}

public class R2
{
    public List<Need2> needs { get; set; }
    public List<Sku2> skus { get; set; }
}

public class Need3
{
    public string need { get; set; }
    public int score { get; set; }
    public string category1 { get; set; }
    public string category2 { get; set; }
}

public class Sku3
{
    public double score { get; set; }
    public string category1 { get; set; }
    public string code { get; set; }
    public string category3 { get; set; }
    public string category2 { get; set; }
    public string category4 { get; set; }
}

public class R3
{
    public List<Need3> needs { get; set; }
    public List<Sku3> skus { get; set; }
}

public class Need4
{
    public string need { get; set; }
    public int score { get; set; }
    public string category1 { get; set; }
    public string category2 { get; set; }
}

public class Sku4
{
    public double score { get; set; }
    public string category1 { get; set; }
    public string code { get; set; }
    public string category3 { get; set; }
    public string category2 { get; set; }
    public string category4 { get; set; }
}

public class R4
{
    public List<Need4> needs { get; set; }
    public List<Sku4> skus { get; set; }
}

public class RootObject
{
    public R1 r1 { get; set; }
    public R2 r2 { get; set; }
    public R3 r3 { get; set; }
    public R4 r4 { get; set; }
}
【秦时明月】 | 园豆:760 (小虾三级) | 2014-05-29 11:49

谢谢,不过RootObject deserializeObject = JsonConvert.DeserializeObject<RootObject>(jsonString);貌似还是报错了。。

支持(0) 反对(0) 菜菜菜菜鸟飞不动 | 园豆:81 (初学一级) | 2014-05-29 13:10
0

路过...不是搞C#,呵呵!

Even丶 | 园豆:218 (菜鸟二级) | 2014-05-29 13:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册