nuget獲取Newtonsoft.Json github地址: "Newtonsoft.Json" ...
nuget獲取Newtonsoft.Json
github地址:Newtonsoft.Json
public static void Test1()
{
/* 文本格式如下 代碼實現目的:
1、VR 對象中是否包含ProjectId
2、取ProjectId下的值
{
"VR": {
"ProjectId": {
"txt_s": "工程項目的名稱編號Id",
"value": "01"
},
"ProjectObject": {
"ProjectTypeName": {
"name": "12企業類別1",
"txt_s": "企業類別名稱"
},
"txt_s": "企業類別對象"
},
"ProjectTitle": {
"txt_s": "工程項目的名稱(Title信息)",
"value": "01"
},
"UserId": {
"txt_s": "用戶的Id",
"value": "01"
}
}
}
*/
var str = @"%7b+%22VR%22%3a+%7b%22ProjectId%22%3a+%7b%22txt_s%22%3a+%22%e5%b7%a5%e7%a8%8b%e9%a1%b9%e7%9b%ae%e7%9a%84%e5%90%8d%e7%a7%b0%e7%bc%96%e5%8f%b7Id%22%2c+%22value%22%3a+%2201%22+%7d%2c+%22ProjectObject%22%3a+%7b%22ProjectTypeName%22%3a+%7b%22name%22%3a+%2212%e4%bc%81%e4%b8%9a%e7%b1%bb%e5%88%ab1%22%2c+%22txt_s%22%3a+%22%e4%bc%81%e4%b8%9a%e7%b1%bb%e5%88%ab%e5%90%8d%e7%a7%b0%22+%7d%2c+%22txt_s%22%3a+%22%e4%bc%81%e4%b8%9a%e7%b1%bb%e5%88%ab%e5%af%b9%e8%b1%a1%22+%7d%2c+%22ProjectTitle%22%3a+%7b%22txt_s%22%3a+%22%e5%b7%a5%e7%a8%8b%e9%a1%b9%e7%9b%ae%e7%9a%84%e5%90%8d%e7%a7%b0(Title%e4%bf%a1%e6%81%af)%22%2c+%22value%22%3a+%2201%22+%7d%2c+%22UserId%22%3a+%7b%22txt_s%22%3a+%22%e7%94%a8%e6%88%b7%e7%9a%84Id%22%2c+%22value%22%3a+%2201%22+%7d+%7d%7d";
//上述文本是編碼之後的,方便調試
str = HttpUtility.UrlDecode(str, Encoding.UTF8);
var jobject = JObject.Parse(str);
var projectId = jobject.SelectToken("VR.ProjectId");
//VR 對象中是否包含ProjectId
if (!projectId.HasValues)
{
//不包含
}
else
{
foreach (var temp in projectId.Children())
{
if (temp.Path.EndsWith("txt_s"))
{
var a = temp.ToObject<string>();
//a 的值是 工程項目的名稱編號Id
}
if (temp.Path.EndsWith("value"))
{
var a = temp.ToObject<string>();
//a 的值是 01
}
}
}
}