C# JObject 的使用生成json字符串

JObject obj = new JObject();
            JObject obj1 = new JObject();

            obj["where"] = obj1;
            obj1["exname"] = "name";//{"exname": "name"}
            obj["skip"] = 0;
            obj["limit"] = 24;
            obj["include"] = new JArray() { "a", "b" };// "include": ["a","b"]
            if (!string.IsNullOrWhiteSpace("keyword"))
            {
                JObject obj2 = new JObject();
                obj1["fileName"] = obj2;
                obj2["like"] = "keyword";
            }
            //至此obj1的值为{"exname": "name","fileName": {"like": "keyword"}}
            obj["order"] = "heatCount desc";
            string json = obj.ToString();

 
  

你可能感兴趣的:(C#)