Home > Net >  Json return values
Json return values

Time:10-05

To ask you
{\ "log_id " : 7616486206799412622, \ "results " : [{\ "location " : {\ "height " : 543, \ "left " : 1312, \ "top " : 644, \ "width " : 669}, \ "name " : \ "1234 ", \ "score " : 1}]} \ n}
"

{\ "log_id " : 1587313827561704838, \ "results " : []} \ n}
"
If the second return value was submitted to the wrong

Code:
JavaScriptSerializer js=new JavaScriptSerializer ();//instantiate a class can be serialized data
ToJsonMy3 list=js. DeserializeString log_id=list. Log_id;
List Named orderdetail=list. The results;
String name=named orderdetail [0]. Name;
String score=named orderdetail [0]. Score;

Public struct ToJsonMy3
{
Public string log_id {get; The set; }
Public List The results;//array processing
//public results results;
}

Public struct the results
{
Public string name {get; The set; }
Public string score {get; The set; }
Public List The location;//array processing

}
Public struct location
{
Public string top {get; The set; }
Public string left the {get; The set; }
Public string width {get; The set; }
Public string height {get; The set; }

}

Thank you. What should I do

CodePudding user response:

Do you want to see your json string really contains \ n, and there should be a comma between the second and first article

[{" log_id: "7616486206799412622," results ": [{" location" : {" height ": 543, the" left ": 1312," top ": 644, the" width ": 669}," name ":" 1234 ", "score" : 1}]},
{" log_id: "7616486206799412622," results ": [{" location" : {" height ": 543, the" left ": 1312," top ": 644, the" width ": 669}," name ":" 1234 ", "score" : 1}]}]

CodePudding user response:

Wrong, it is two kinds of results returned
1: {" log_id: "1594288546244956330," results ": []}

2: {" log_id: "30078127253539397," results ": [{" location" : {" height ": 543, the" left ": 1312," top ": 644, the" width ": 669}," name ":" cat ", "score" : 0.9970706701278687}]}

Return parameter
Whether a field will choose type description
Log_id was the only log id number for problem positioning
Results no array (object) to identify the result array
+ name no string classification name
Confidence + score no number
+ location no
+ + left no number detected target distance of the body area to the border of the image left
+ + top n number of detected target distance of the body area to the border of the picture
+ + width or the width of the number of detected target the body area
+ + height or number of detected target the height of the body area

Results the correct empty words

CodePudding user response:

Deserialization obviously not an error
But the second actually there is no data
List Named orderdetail=list. The results;
String name=named orderdetail [0]. Name;
String score=named orderdetail [0]. Score;
This named orderdetail no natural element cannot be named orderdetail [0]

CodePudding user response:


No problem,

CodePudding user response:

String name=named orderdetail [0]. Name;
String score=named orderdetail [0]. Score;
This named orderdetail no natural element cannot be named orderdetail [0]

How to deal with it? Judgement more? There is no element NAME=""

CodePudding user response:

The parameters of the null value with newtonsoft a ignored

CodePudding user response:

refer to 6th floor asq985 response:
with newtonsoft a ignore null parameter


Can you give the reference code?

CodePudding user response:


An error, of course,,, is not a json data format! Json is key/value pair mode,,, good check data!!!!!!!!!!!!!!!!!!!!! Your data is not a json string data type,,,, is a string of data,,!!!!!!!!!!!!!!!!!!!! Check the data

CodePudding user response:

reference 4 floor asq985 response:

No problem


Could you tell me how to put the string under the json data into objects
{" log_id: "30078127253539397," results ": [{" location" : {" height ": 543, the" left ": 1312," top ": 644, the" width ": 669}," name ":" cat ", "score" : 0.9970706701278687}]}
Get log_id, height, left, top, width, and the name, the value of the score

CodePudding user response:

R2. Log_id

R2. The result [0]. Height

CodePudding user response:

reference 4 floor asq985 response:

No problem


Can, this,

If you don't want to define entity class, you use the

Dynamic type deserialization can also be directly,

CodePudding user response:

Determine the first:
If (named orderdetail. Count & gt; 0)
{
String name=named orderdetail [0]. Name;
String score=named orderdetail [0]. Score;
}

CodePudding user response:

Or the string name=named orderdetail. Count & gt; 0? Named orderdetail [0]. Name: "";
String score=named orderdetail. Count & gt; 0? Named orderdetail [0]. Score: "";
  •  Tags:  
  • C#
  • Related