Home > Net >  When I do not know if the json contain certain key, how to the fastest to judge the value of this ke
When I do not know if the json contain certain key, how to the fastest to judge the value of this ke

Time:10-07

Can only be judged whether you the first key, any judgment value again, right?
 JObject Json=JObject. Parse (text); 
If (Json. Either ContainsKey (" specific key ") & amp; & Json [r]. "specific" ToString ()=="specific value")
//contains a specific "key" and the key has a value of "specific value" meet the conditional
The else
//does not contain a particular key or contains the key, but the key values are not for "specific value does not meet the conditions of"
is there any way a judgment come out? Such as writing something like this:
 if (Json [" specific key]==JValue (" specific value "))//compile by 

CodePudding user response:

"Conditions of Null operator
"
If (Json/" specific "? . ToObject ()=="specific value")
{
}

CodePudding user response:

reference 1st floor github_36000833 response:
"Null conditional operator
"If (Json/" specific "? . ToObject ()=="specific value")
{}
well, again, please, how do you determine the Json first key in the key name is what?

CodePudding user response:

Regular directly determine not faster

CodePudding user response:

Is easier to understand: var firstKey=Json. The Properties () FirstOrDefault ()? .name;
Less code: var firstKey=(Json. The First as JProperty)? .name;

CodePudding user response:

In fact, I want to ask, what is the meaning of the fastest?
Code short, or fast?

CodePudding user response:

Fast? There is no fast

Turn this into an xpath, or class of SQL query is no problem, such as a lot of no direct query of database support json, even said MSSQL can also support json query

Problems with fast, not fast, are internal traversal, at most is likely to mapping, internal index,

CodePudding user response:

reference 5 floor is nu month god reply:
actually I want to ask, what is the meaning of the most quickly?
Code short, or fast?

May feel
The code short=speed

CodePudding user response:

So, nuget casually use "json xpath" and "json SQL" search can find a lot of, as for quickly, not necessarily a json this universal type duck, you in addition to rebuild the index map, no way to faster, at most probably is write your own stuff, the structure of the linq to emit or similar expressions, the internal code automatically determine to return

CodePudding user response:

Judge can be converted to a string? Such as a string. The Contains (" \ \ ":" XXX ");
  •  Tags:  
  • C#
  • Related