json.net例子
1 JObject output = new JObject(); 2 if (dt.Rows.Count > 0) 3 { 4 output = new JObject 5 { 6 //new JProperty("total",10), 7 new JProperty("success",true), 8 new JProperty("items",new JArray( 9 from p in dt.AsEnumerable() 10 select new JObject( 11 new JProperty("iden",Convert.ToInt32(p["ylin_0"])), 12 new JProperty("shangpbm",Convert.ToString(p["itmref_0"])), 13 new JProperty("shangpmc",Convert.ToString(p["itmdes1_0"])), 14 new JProperty("guig",Convert.ToString(p["itmdes3_0"])), 15 new JProperty("fenl",Convert.ToString(hpd.GetFenlList(p["tsicod_0"].ToString()).Rows[0]["texte_0"].ToString())), 16 new JProperty("fenlnew",Convert.ToString(p["tsicodnew_0"])) 17 ) 18 ) 19 20 ) 21 }; 22 } 23 return output.ToString(); 24 } 25 // { 26 // "success": true, 27 // "items": [ 28 // { 29 // "iden": 2000, 30 // "shangpbm": "00001", 31 // "shangpmc": "hx", 32 // "guig": "750", 33 // "fenl": "ltt", 34 // "fenlnew": "02" 35 // }, 36 // { 37 // "iden": 1000, 38 // "shangpbm": "000008", 39 // "shangpmc": "cc", 40 // "guig": "66", 41 // "fenl": "ltt", 42 // "fenlnew": "01" 43 // } 44 // ] 45 //}