mono touch中处理json字符串

来源:互联网 发布:红米清空用户数据99 编辑:程序博客网 时间:2024/06/10 04:17

有不明白的地方欢迎入群 347636249 探讨

需要引用System.Json.dll文件:

private string jonstr=@"{    ""totalCount"": ""11"",    ""articleInfoList"": [{        ""Articleid"": ""134"",        ""Articletitle"": ""生态农业或成中央农村会议焦点"",        ""articleContent"": ""http://xxxxxxxxx/article/padarticle.aspx?id=134"",        ""Articlechannel"": ""80"",        ""Articlecreatedate"": ""2013/12/6 0:00:00"",        ""Articleimg"": """",        ""ArticleAuthor"": ""超级管理员"",        ""outline"": ""近日,中央就农业生态问题和农业可持续发展模式进行了密集调研,各级地方政府农业部门纷纷成立农村环境督查组对相关项目进行检查。多位权威专家在接受《经济参考报》记者采访时表示,一年一度的中央农村工作会议即将召开,预计生态农业将成为会议的一大焦点。"",        ""clicknumber"": ""71""    },    {        ""Articleid"": ""130"",        ""Articletitle"": ""中纪委今起开展网上党风廉政建设民意调查"",        ""articleContent"": ""http://xxxxxxxxxxx/article/padarticle.aspx?id=130"",        ""Articlechannel"": ""80"",        ""Articlecreatedate"": ""2013/11/8 0:00:00"",        ""Articleimg"": ""http://xxxxxxxxxxx/Fwadmin/Images/Attach/20131126151752777.jpg"",        ""ArticleAuthor"": ""超级管理员"",        ""outline"": """",        ""clicknumber"": ""16""    }]}";

说明:上面的json串并不标准,由于是直接复制的json字符串到编辑器中,Xamarin会自动转译,不过不会有影响,这里只是测试,自己测试下就知道,当然标准的json最好了。

private List<ArticleModel> parseJsonData(){JsonValue jv = JsonObject.Parse (jonstr);var rs = (from t in (JsonArray)jv ["articleInfoList"]        let r = t as JsonObject        select new ArticleModel {Articleid=t["Articleid"],Articletitle = t["Articletitle"],ArticleContent =t["articleContent"],Articlechannel = t["Articlechannel"],Articlecreatedate=t["Articlecreatedate"],Articleimg=t["Articleimg"],ArticleAuthor=t["ArticleAuthor"],Outline=t["outline"],ClickNumber = t["clicknumber"]}).ToList ();return rs;}


0 0
原创粉丝点击