- The difference between Jobect and Jsondata
Jsondata is a simplified version of Jobect
2. Bug that the conversion process is easy to make
Jsondata: cannot be converted when there is null inside
Solution: Jsondata TEAMJD = Jsonmapper.toobject (Finddoctor ("0", OrgID). Replace (": null", ": \" \ ")"); Replace NULL in Jsondata with ""
Jobect: Conversion to Jobect failed
Solution: The reason for the failure is that the conversion object is an array to be converted to Jarray Jarray jarray=jarray.parse (str);
Jobect:jarray[0] cannot be converted directly to Jobect
Solution: Jobject jobject = jarray[0] as jobject;
Jobect: Array cannot be evaluated with count when Jobect object exists inside
Solution:
foreach (jtoken field in jobject["Data" ["doctors"])
{
if (field["name"]. ToString ()). Equals (Docname.trim ()))
{
Doctorid = field["id"]. ToString ();
Break
}
}
3. Determine that the JSON value is empty
JOBECT:JB. ToString (). Equals ("") returns Jsonobect if it is not empty
Jsondata:jd. Count==0
Conversion of 4.json objects
Jsondata: When an array exists inside
json["userfamilyhistory"] = new Jsondata ();
json["Userfamilyhistory"]. Setjsontype (Jsontype.array);
json["Userfamilyhistory"]. ADD (userfamilyhistory);
Jobect: When an array exists inside
list<jobject> listhistory = new list<jobject> ();
Object other = new Jobject ();
...............
Listhistory.add (other);
Jobject.add (New Jproperty ("History", listhistory));
Note: Jsonconvert.serializeobject () can convert a class, DataTable directly into a JSON string
5. Tips for JSON applications
CREATE table from JSON private void CreateTable (Jarray jarray,string tabname) {jobject jobject = jarray[0] as jobject;// Configure the Contract table DataTable SIGNTB = new DataTable (tabname); foreach (var item in Jobject) SIGNTB.COLUMNS.ADD (item. Key), foreach (Jobject obj in Jarray) {DataRow NewRow = Signtb.newrow (); foreach (var item in obj) {newrow[item. Key] = Item. Value;} SIGNTB.ROWS.ADD (NewRow);} Commonrse.ds[tabname] = Signtb.copy ();}
Use of JSON (Jobect,jsondata,jarray)