JObject对json的操作

一,需去程序集添加using Newtonsoft.Json.Linq;引用

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;
using System.Net;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string str = "{'a':'aaa','b':'bbb','c':'ccc'}";
        JObject jo = JObject.Parse(str);
        if (jo.Property("a") == null || jo.Property("3").ToString() == "")
        {
            Label1.Text = "键值key不存在!";
        }


        IEnumerable<JProperty> properties = jo.Properties();
        foreach (JProperty item in properties)
        {
            Label2.Text += item.Name + ":" + item.Value;
        }

        Label3.Text = jo.Value<string>("a");
    }
}

 

posted @ 2016-08-30 14:45  叶丶梓轩  阅读(1703)  评论(0编辑  收藏  举报