objectid ID { Get ; set ;} string title { Get ; set ;} int depth { Get ; set ;} string path { Get ; set ;}
From the class definition, we can see that the storage structure of the Tree node mainly has four items: ID is a unique number, title is the node name, and depth is the depth of the node, PATH is the full path of the node.
The following describes the subnode query operations. The Code is as follows:
Private String List (httpcontext context ){ String Nodeid = contex
(jsreader); // deserialization of json is then converted to JObject Console. writeLine (jo. toString ();} Console. read ();}}}
Running result:
2. Linq To Json
Main classes of linq to json:
1. JObejct: json object
2. JArray: used to operate json Arrays
3. JValue: Value in the array
4. JProperty: The property of a json object, which usually exists in a dictionary similar to a key or value.
5. JToken: used to store the result value of the linq Query
Th
Jproperty
Represents an attribute in an object, in the form of "Key/value"
Jtoken
Results for storing LINQ to JSON queries
1. Create a JSON object
Jobject staff = new Jobject ();
Staff. ADD (New Jproperty ("Name", "Jack"));
Staff. ADD (New Jproperty ("Age");
Staff. ADD (Ne
LINQ to JSON is used to manipulate JSON objects. You can use it to quickly query, modify, and create JSON objects. When the JSON object content is complex and we only need a small subset of the data, consider using LINQ to JSON to read and modify portions of the data instead of deserializing all.two. Creating JSON arrays and objectsBefore you make LINQ to JSON, let's first look at the classes used to manipulate LINQ to JSON.
Class name
Description
Jobject
what is Linq to JSON for?LINQ to JSON is used to manipulate JSON objects. You can use it to quickly query, modify, and create JSON objects. When the JSON object content is complex and we only need a small subset of the data, consider using LINQ to JSON to read and modify portions of the data instead of deserializing all.two. Creating JSON arrays and objectsBefore you make LINQ to JSON, let's first look at the classes used to manipulate LINQ to JSON.
Class name
Description
Ext. direct. in DLL Source Code , the author finds that the "result" of the directresponse class is an object, in this example, the author changes the returned data type of the method called by the client to jobject, but an error occurs when the following statement is executed: return jsonconvert. serializeobject (response); it seems that you need to modify it here, so I changed the above sentence in the directprocessor class to the following code: copy Code the code is as follows: if (r
Setting values and creating objects and arrays one at a time gives all control but it's more verbose than other opt Ions. Creating JSON Copy imagecopy 1JArray array = new Jarray (); 2JValue Text = new Jvalue ("Manual text"); 3JValue date = new Jvalue (New DateTime (2000, 5, 23)); 4 5array. ADD (text); 6array. ADD (date); 7 8string JSON = array. ToString (); 9//[ 10//"Manual text", 11//"2000-05-23t00:00:00" 12//] Creating JSON with LINQ Declaratively creating JSON objects using LINQ is a fast-t
able to solve this problem on the server side. In the source code of Ext.Direct.dll, the author found that the definition type of "result" of Directresponse class is an object, so the author modifies the return data type of the method called by the client in the example to Jobject. However, an error occurs when you execute the following statement:
Return JsonConvert. SerializeObject (response);
It seems that there needs to be modified, so the author of the Directprocessor class in the above sen
, Jsonobject, Jsonvalue
System.json
Can only be used in Silverlight
Is
JsonConvert, Jarray, Jobject, Jvalue, Jproperty
Newtonsoft.json
General
Is
Preparing dataEntity class:[DataContract]PublicClass Person {[DataMember (Order =0, isrequired =true)] public string Name { get; set;} [DataMember (Order = 1)] public int Age { get; set;} [DataMember (Order = 2)] public bool Alive { get; set;} [DataMember
, Jsonobject, Jsonvalue
System.json
Can only be used in Silverlight
Is
JsonConvert, Jarray, Jobject, Jvalue, Jproperty
Newtonsoft.json
General
Is
Preparing dataEntity class:[DataContract]PublicClass Person {[DataMember (Order =0, isrequired =true)] public string Name { get; set;} [DataMember (Order = 1)] public int Age { get; set;} [DataMember (Order = 2)] public bool Alive { get; set;} [DataMemb
. mapPath (root + path); total = dir. getFiles (). count (); var q = dir. getFiles (). select (m => new {filename = m. name, modify = m. lastWriteTime, size = m. length }). asQueryable (). orderBy (sort ). skip (start ). take (50); foreach (var c in q) {ja. add (new JObject {new JProperty ("path", path), new JProperty ("filename", c. filename), new JProperty ("mo
value = data. v |; $ Value. val (value); if (value! =) $ Value. change (); // call the value change event}, parse: function (data) {var parsed = []; for (var I = 0; I
Data returned from the background
Private string GetAutoCompleteUser (string type) {string keys = request [q]; int count = Convert. toInt32 (request [limit]); // The number of returned results can be understood as the page size string tmpOrgIDs _ = request [OrgIDs]; int page = 1; int. tryParse (request [page], out page); //
order to keep the category at the top, it is best to exclude it during the query and add it to the result. The code is modified as follows:
Q = Dc. t_category.where (M => M. hierarchylevel = 0 M. categoryid! = 10000 M. State = 0). orderby (M => M. Title );
Now we need to write data to Ja. Because we need to write objects in the same format multiple times, it is better to separate the writing objects into a method. The Code is as follows:
Privatejobject writenode (int id, string text, int par
good choice to overload this method. The Code is as follows:
Publicstatic JObject WriteJObjectResult (bool success, int total, string message, JArray data)
{
Return new JObject {
NewJProperty ("success", success ),
New JProperty ("total", total ),
New JProperty ("Msg", message ),
New JProperty ("data", data)
};
}
Now you can complete the code for the List metho
records,
MSG: error message,
Data: An array composed of records on the current page
}
In the structure, success indicates whether the returned results are successful. If it fails, you can use MSG to obtain the error message. If it succeeds, it reads data from the data. The total in the structure is very important. The client will calculate the number of pages based on this value, so it must be returned correctly, otherwise the page will be messy.
To adapt the writejobjectresult method created
);
String name = jsonObj ["name"]. ToString ();
String age = jsonObj ["age"]. ToString ();
String city = (JObject) jsonObj ["addr"]) ["city"]. ToString ();
String province = (JObject) jsonObj ["addr"]) ["province"]. ToString ();
Why is this json dynamic? For example, you can enter a json file, such as {"name": "lily", "age": 23, "addr": {"city": guangzhou, "province ": guangdong}; then let you enter an object, such as city, and then the system will output the guangzhou value. In this case, json
public string GetJsonValue(JEnumerablestring key){IEnumerator enumerator = jToken.GetEnumerator();while (enumerator.MoveNext()){JToken jc = (JToken)enumerator.Current;if (jc is JObject||((JProperty)jc).Value is JObject){return GetJsonValue(jc.Children(), key);}else{if (((JProperty)jc).Name == key){return ((JProperty)jc).Value.ToString();}}}return null;}At the tim
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.