導航:首頁 > 編程語言 > 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數據相關的資料

熱點內容
設置安卓資源xml的步驟 瀏覽:305
vim怎麼修改文件 瀏覽:683
安卓游戲大型 瀏覽:933
powershell清空文件內容 瀏覽:409
字體在那個文件夾 瀏覽:342
蘋果4真機體驗 瀏覽:551
世界盃買在哪個app 瀏覽:631
魔力寶貝37版本 瀏覽:115
迷你編程的兌換碼是什麼 瀏覽:359
換一個文件櫃玻璃大概多少錢 瀏覽:971
什麼是代理網路 瀏覽:805
axure怎麼發布到手機app 瀏覽:227
如何做動漫視頻教程 瀏覽:331
蘋果公司企業架構 瀏覽:152
順豐錄音文件管理在哪裡 瀏覽:521
象山新建網站製作有哪些步驟 瀏覽:686
什麼app可以查化妝品的日期 瀏覽:174
中國移動香港的網路制式 瀏覽:752
編程在五行中屬什麼 瀏覽:54
中青校園app可以發什麼文章 瀏覽:397

友情鏈接