Home > Net >  C # how to obtain the json path without recursive and the value of the path
C # how to obtain the json path without recursive and the value of the path

Time:03-05


{
"Room" : {
"GJAerialView" : "industrial park base,"
"L02Room" : "display assembly workshop,"
"MRoom" : "MI workshop,"
"SMTRoom" : "the SMT workshop,"
"SL03Room" : "multi-functional product assembly workshop,"
"Unknown" : "not configured workshop"
},
"Room1" : {
1 "" GJAerialView1" : "industrial park base,
"L02Room1" : "display assembly workshop 1
"}...
}
Json file fragments as
How we by passing in the background of the key (such as providing the first parameter room. GJAerialView routine returns "industrial base", room1. L02Room1 return "1" display assembly workshop)

keep in mind that don't use recursive

CodePudding user response:

Online, such as recursive has achieved,
 

The first method segment code is as follows (length is introduced into the key according to the '. 'to split the length of the array)
for (int i=0; I & lt; Length; I++)
{
//if it is the first layer, then according to the above the top key for read out the json string
If (I==0)
{
Value_zh_cn=GetJsonStringOrValue (str_zh_cn_json, arrKey [I]);
Value_en=GetJsonStringOrValue (str_en_json, arrKey [I]);
}
Else//if the first layer, then according to the child the key to obtain the above json string or read out values
{
Value_zh_cn=GetJsonStringOrValue (value_zh_cn as string, arrKey [I]);
Value_en=GetJsonStringOrValue (value_en as string, arrKey [I]);
}
}


Public static object GetJsonStringOrValue (string input_json, string key)
{
If (String. IsNullOrEmpty (input_json) | | String. IsNullOrEmpty (key))
Return a string. The Empty;
Input_json=input_json. Replace (" \ r \ n ", string. The Empty);
JavaScriptSerializer serializer=new JavaScriptSerializer ();
Dictionary Json=serializer. DeserializeObject (input_json) as Dictionary;
//here the manager said that the object can be directly take the path of key
The object value.
Json. TryGetValue (key, value) out;
Value=https://bbs.csdn.net/topics/serializer.Serialize (value);

The return value.
}

CodePudding user response:

In fact, I think it's turn objects can also be,,,,
But if you just try out data, then jobject

CodePudding user response:

As for how to decompose room. GJAerialView
This is not,

CodePudding user response:

Regular expression match well

CodePudding user response:

Still think
People choose lenovo according to CSS out of the jquery selector

reference
then people will not according to the XML xmlpath lenovo out a jsonpath out?
The answer is yes

https://goessner.net/articles/JsonPath/

reference
as a net is applied most widely json library Newtonsoft. Json will support him?
The answer is still yes
https://www.newtonsoft.com/json/help/html/QueryJsonSelectToken.htm




CodePudding user response:

refer to the second floor is nu month god reply:
in fact, I think it's turn objects can also be,,,,
But if you just try out data, then jobject

The first is the method of fragment
CTRL + f to find problems in the following sentence
//here the manager said that the object can be directly take the path of the key

CodePudding user response:

Hello World reference 4 floor, response:
regular expression match on the

Write to see

CodePudding user response:

Hello World reference 4 floor, response:
regular expression match on the


This is likely to c # string room1. GJAerialView1 could also be room. GJAerialView

CodePudding user response:

reference 5 floor wanghui0380 reply:
still lenovo
People choose lenovo according to CSS out of the jquery selector

reference
then people will not according to the XML xmlpath lenovo out a jsonpath out?
The answer is yes

https://goessner.net/articles/JsonPath/

The
Quote:

As the most widely as a being of.net json library Newtonsoft. Json will support him?
The answer is still yes
https://www.newtonsoft.com/json/help/html/QueryJsonSelectToken.htm




Don't you want to try myself???????


 JObject o=JObject. Parse (@ {
""" room" ": {
"" GJAerialView" ":" "industrial base", "
L02Room "" :" "display assembly shop", "
"" MRoom" : "" "" "MI workshop,
"" SMTRoom" : "" "" "SMT workshop,
"" SL03Room" : "" "" "multi-functional product assembly workshop,
"" unknown" ", "not configured" workshop ""
},
"" room1" ": {
GJAerialView1 ":" 1 "" "" industrial park base,
"" L02Room1" ":" "display assembly workshop 1" "
}
} ");

String name=(string) grown electToken (" room. GJAerialView ");

Guess what, the result is what!!!!!

CodePudding user response:

refer to the second floor is nu month god reply:
in fact, I think it's turn objects can also be,,,,
But if you just try out data, then jobject


Thank you very much also attentively to knock code help intuitive show

But we are the incoming string room1. GJAerialView1 could also be room. GJAerialView


references 9 f wanghui0380 response:
Quote: refer to the fifth floor wanghui0380 reply:
still lenovo
People choose lenovo according to CSS out of the jquery selector

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related