導航:首頁 > 編程語言 > net獲取json數據

net獲取json數據

發布時間:2025-03-03 20:35:26

『壹』 .net 獲取json的數據有為null的,然後就報錯,怎麼判斷他是否為null

可以重新賦值。 如果json={"SSGM":null} JSONObject jsonObj = new JSONObject(json); String SSGM = jsonObj.get("SSGM");//獲取JSON中SSGM的值便於判內斷 if(null == SSGM) { jsonObj .put("SSGM","")//如果為容null那麼將SSGM的值賦值為"" } 不知

『貳』 asp.net mvc中怎麼樣解析 json

public static DataTable JsonToDataTable(string strJson)
{
//取出表名
Regex rg = new Regex(@"(?<={)[^:]+(?=:\[)", RegexOptions.IgnoreCase);
string strName = rg.Match(strJson).Value;
DataTable tb = null;
//去除表名
strJson = strJson.Substring(strJson.IndexOf("[") + 1);
strJson = strJson.Substring(0, strJson.IndexOf("]"));

//獲取數據
rg = new Regex(@"(?<={)[^}]+(?=})");
MatchCollection mc = rg.Matches(strJson);
for (int i = 0; i < mc.Count; i++)
{
string strRow = mc[i].Value;
string[] strRows = strRow.Split(',');

//創建表
if (tb == null)
{
tb = new DataTable();
tb.TableName = strName;
foreach (string str in strRows)
{
DataColumn dc = new DataColumn();
string[] strCell = str.Split(':');
dc.ColumnName = strCell[0].ToString();
tb.Columns.Add(dc);
}
tb.AcceptChanges();
}

//增加內容
DataRow dr = tb.NewRow();
for (int r = 0; r < strRows.Length; r++)
{
dr[r] = strRows[r].Split(':')[1].Trim().Replace(",", ",").Replace(":", ":").Replace("\"", "");
}
tb.Rows.Add(dr);
tb.AcceptChanges();
}

return tb;
}
用法:
htmlBody 的例子:
{"Mobile":"15655959999","QueryResult":"True","Province":"安徽","City":"黃山","AreaCode":"0559","PostCode":"245000","Corp":"中國聯通","Card":"GSM"}
string json = "{table:" + htmlBody + "}";
DataTable dt = Common.JsonExtensions.JsonToDataTable(json);

datdatable的數據會取了吧!

閱讀全文

與net獲取json數據相關的資料

熱點內容
一個文件內容替換另一個文件 瀏覽:288
ios8最好的版本 瀏覽:400
錄屏決定文件大小的是什麼 瀏覽:322
數據用不了是哪裡壞掉了 瀏覽:310
百度網盤文件傳輸格式 瀏覽:455
蘋果系統txt文件 瀏覽:629
家裝網站怎麼設計 瀏覽:202
adc指令微程序 瀏覽:487
名片模板word 瀏覽:635
怎麼把文件夾上鎖 瀏覽:331
我不會英語怎麼編程 瀏覽:895
c盤和文件大小 瀏覽:63
maya工具架怎麼調出來 瀏覽:191
文件系統壞了怎麼辦 瀏覽:261
小公司網路布線 瀏覽:515
怎麼用二維碼編程 瀏覽:341
f9b文件能用手機看嗎 瀏覽:364
手機暴風視頻文件夾 瀏覽:394
vsftpdlinux下載文件 瀏覽:948
文件名修改後快捷方式還可以用嗎 瀏覽:387

友情鏈接