using (MProc action = new MProc(sb.ToString(), strcon)) { MDataTable mdt = action.ExeMDataTable(); // jshelper.Add("spxx", mdt.ToJson()); if (mdt.Rows.Count > 0) { jshelper.Add("rowcount", mdt.Rows.Count.ToString()); jshelper.Add("total", mdt.Rows.Count.ToString()); jshelper.Add("errorMsg", ""); jshelper.Add("success", "true"); jshelper.Add("success1", "true"); JsonHelper js2 = new JsonHelper(); foreach (var mrow in mdt.Rows) { for (int i = 0; i < mrow.Columns.Count; i++) { js2.Add(mrow[i].ColumnName, mrow[i].Value.ToString()); } strsql = string.Format("Select iSalePrice1,iSalePrice2,iSalePrice3,iSalePrice4,iSalePrice5,iSalePrice6,B.cComUnitName As cUnit,iInvid jjid From Inventory2Price A Left Join v_ComputationUnit B On A.iUnitid = B.iUnitid where iInvid={0}", mrow["iInvid"].Value); action.ResetProc(strsql); MDataTable mdtgroup = action.ExeMDataTable(); if (mdtgroup.Rows.Count > 0) js2.Add("group", mdtgroup.ToJson()); //js2.AddBr(); } jshelper.Add("rows", js2.ToString()); } return jshelper.ToString(); }
这样子写 rows 并不是数组,请指教,谢谢
1:js.add(key,value,第三个参数可以选择加不加引号)
如果是value是json或[],第三个参数要设置为不加引号,不然会被当成字符串。
2:js.ToString或MDataTable的ToJson方法,都有参数,指明是否最后输出数组(就是补上[])