苏飞论坛

标题: 两个问题,Json 解析成 List [打印本页]

作者: wnhost    时间: 2015-2-14 19:36
标题: 两个问题,Json 解析成 List
第一个问题

如何把Json 解析成 List

怎么写


第二个问题


content:[{ wordID: 26297, word: \"A\", mean: \"a.一,一个,一只,一件.\", phonetic: \"2eI,E3\", example: \"<i>1.</i> I don't care what <font color=#cc0066>a</font> car looks like as long as it gets me from <font color=#cc0066>A</font> to B.<br>&nbsp;&nbsp; <font color=#223322>我倒不在乎汽车的样子, 只要能把我从一处载到另一处就行了.<br></font><i>2.</i> Would you do me <font color=#cc0066>a</font> favor?<br>&nbsp;&nbsp; <font color=#223322>你能帮我一个忙吗?<br></font>\", picture: \"Attachments/Images/A.png\" },{ wordID: 26297, word: \"A\", mean: \"a.一,一个,一只,一件.\", phonetic: \"2eI,E3\", example: \"<i>1.</i> I don't care what <font color=#cc0066>a</font> car looks like as long as it gets me from <font color=#cc0066>A</font> to B.<br>&nbsp;&nbsp; <font color=#223322>我倒不在乎汽车的样子, 只要能把我从一处载到另一处就行了.<br></font><i>2.</i> Would you do me <font color=#cc0066>a</font> favor?<br>&nbsp;&nbsp; <font color=#223322>你能帮我一个忙吗?<br></font>\", picture: \"Attachments/Images/A.png\" },{ wordID: 26297, word: \"A\", mean: \"a.一,一个,一只,一件.\", phonetic: \"2eI,E3\", example: \"<i>1.</i> I don't care what <font color=#cc0066>a</font> car looks like as long as it gets me from <font color=#cc0066>A</font> to B.<br>&nbsp;&nbsp; <font color=#223322>我倒不在乎汽车的样子, 只要能把我从一处载到另一处就行了.<br></font><i>2.</i> Would you do me <font color=#cc0066>a</font> favor?<br>&nbsp;&nbsp; <font color=#223322>你能帮我一个忙吗?<br></font>\", picture: \"Attachments/Images/A.png\" }]
怎么得到content:下有多少个数组,没办法用,号,mean里有的时候有,号,

作者: guanzhuyu    时间: 2015-2-15 10:03
可否提供一个完整的json ? 给你个参考
{
    "title": "title",
    "background": {},
    "design_width": 720,
    "design_height": 1137,
    "sys_loader": {},
    "user_loader": {
        "elements": [
            {
                "x": 0,
                "y": 0,
                "w": 360,
                "h": 1137,
                "animal": {
                    "in": {},
                    "condition": {},
                    "out": {
                        "function": "flyInto",
                        "dir": "left",
                        "time": 1,
                        "reverse": 1
                    }
                },
                "content": {
                    "type": "image",
                    "src": "image/leftDoor.jpg"
                }
            },
            {
                "x": 360,
                "y": 0,
                "w": 360,
                "h": 1137,
                "animal": {
                    "in": {},
                    "condition": {},
                    "out": {
                        "function": "flyInto",
                        "dir": "right",
                        "time": 1,
                        "reverse": 1
                    }
                },
                "content": {
                    "type": "image",
                    "src": "image/rightDoor.jpg"
                }
            }
        ]
    },
    "viewportfixtype": "minfix",
    "global_element": {
        "music_toggle": {
            "x": 566,
            "y": 10,
            "w": 64,
            "h": 64,
            "content": {
                "play_src": "image/playicon.png",
                "pause_src": "image/pauseicon.png",
                "music_url": "music/bgmusic.mp3"
            }
        },
        "flip_button": {
            "x": 343,
            "y": 1060,
            "w": 35,
            "h": 32,
            "content": {
                "src": "image/nextpageicon.png"
            }
        },
        "page_indicator": {
            "x": 30,
            "y": 10,
            "w": 114,
            "h": 682,
            "content": {
                "src": "image/time2.png"
            }
        }
    },
    "touchway": "horizo123ntal",
    "page_stack": {
        "pagechangeanimal": "pca106_v",
        "pages": [
            {
                "background": {
                    "image": "url(image/page1_bg.jpg)"
                },
                "elements": [
                    {
                        "x": 53,
                        "y": 600,
                        "w": 614,
                        "h": 285,
                        "animal": {
                            "in": {
                                "function": "float",
                                "time": 1
                            },
                            "condition": {
                                "function": "rotate3d",
                                "time": 1
                            },
                            "out": {
                                "function": "farToNear",
                                "time": 1,
                                "reverse": 1
                            }
                        },
                        "content": {
                            "type": "image",
                            "src": "image/page1_e1.png"
                        }
                    }
                ]
            },
            {
                "background": {
                    "image": "url(image/page2_bg.jpg)"
                },
                "elements": [
                    {
                        "x": 14,
                        "y": 756,
                        "w": 692,
                        "h": 756,
                        "animal": {
                            "in": {
                                "function": "rotate3d",
                                "time": 1
                            },
                            "condition": {
                                "function": "rotate3d",
                                "time": 1
                            },
                            "out": {
                                "function": "glide",
                                "time": 1,
                                "reverse": 1
                            }
                        },
                        "content": {
                            "type": "component.album_01",
                            "imgs": [
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                },
                                {
                                    "icon": "image/loading_icon1.png",
                                    "bg": "image/loading_icon2.png"
                                }
                            ],
                            "imgW": 100,
                            "imgH": 100
                        }
                    }
                ]
            }
        ]
    }
}
我这里是获取imgs下数组的长度。

string json = File.ReadAllText("data.js");
            JObject obj = JObject.Parse(json);
            JToken o1 = obj["page_stack"]["pages"][1]["elements"][0]["content"]["imgs"];
            JArray ja = (JArray)o1;


            Console.WriteLine(ja.Count);
作者: baichong6730165    时间: 2015-2-15 10:32
我只是路过打酱油的。
作者: wnhost    时间: 2015-2-15 16:32
感觉二楼,问题解决,




欢迎光临 苏飞论坛 (http://www.sufeinet.com/) Powered by Discuz! X3.4