.NET JSON 截取部分解析
对于一个json文件,一般的通过JsonConvert.DeserializeObject<>()转换成类型,如果需要只将其中某个键值对解析成C#类型,可参考如下:
string json = "{\"G_1913\":\"1\",\"G_0108\":\"1\",\"G_0001\":\"1\",\"G_1803\":\"3\","DataSettings": { "RTDBConnectionAdS": "1", "RTDBConnectionAdngHuajin": "1", "StdConnectionAdtring": "1", "AuthPnEnum": "2", }}"; var data= JObject.Parse(json.Replace(" ", ""));
var result= data["DataSettings"].ToString();
var res = JsonConvert.DeserializeObject<DataSettings>(datasettingss);
成功解析!
2021-01-04