Home > Net >  C # parse json
C # parse json

Time:11-05

JSON string below

[{" rowValue ": [{" the pop3access.componenttype" : "DepartmentField", "label" : "the expense department", "extendValue" : [{12, "number" : "name" : "the business of four", "id" : "104380371"}], "value" : "the business of four", "key" : "DepartmentField - K371IHGJ"}, {" the pop3access.componenttype ":" TextareaField ", "label" : "use", "value" : "the deposit replacement", "key" : "payment for"}, {" the pop3access.componenttype ":" DDSelectField ", "label" : "the currency of payment", "extendValue" : {" key ":" option_0} ", "value" : "yuan", "key" : "DDSelectField - K371IHGN"}, {" the pop3access.componenttype ":" MoneyField ", "label" : "payment amount (RMB)", "value" : "370000", "key" : "MoneyField - K371IHGO}]}]

Definition of the class the following
Public class extendValue
{
Public int number {get; The set; }
Public string name {get; The set; }

Public string id {get; The set; }

Public string key {get; The set; }
}

Public class rowValue
{
Public string the pop3access.componenttype {get; The set; }
Public string label {get; The set; }
public List ExtendValue {get; The set; }
Public string value {get; The set; }
Public string key {get; The set; }
}




Parsing code below
JavaScriptSerializer JSSS=new JavaScriptSerializer ();
List RowValueItems=JSSS. Deserialize (recValues. Value. The ToString ());
Foreach (rowValue rowValueItem in rowValueItems)
{}

//the code above, rowValue the attribute value is empty, all not parsing process, what is the problem, the column name what didn't see what is wrong, could you tell me what's the problem?
thank you

CodePudding user response:

Copy json, open vs, editing, selective paste, paste json for class,
Then the class, can directly use,

If you must use your own rowValue, then compare the generated class, change the good,

CodePudding user response:

RecValues. Value. The ToString () Value is equal to the above the json string??

CodePudding user response:

If you recValues. Value. The ToString () of the json string Value is equal to the above, that you want to convert the type of actually should be: List>

 
List> List=JSSS. Deserialize> (json);
//the list [0] [" rowValue "] [0]. The pop3access.componenttype;


Otherwise, from the json string you have to put in front of: [{" rowValue ": and the back of the}] take out, otherwise the data format in

CodePudding user response:

RecValues. Value. The ToString () Value is equal to the above the json string

List> List=JSSS. Deserialize> (json);
It still won't do,

The list of the Count directly returns 0

CodePudding user response:

Oh, please take out [{" rowValue ": after the entity class definition?

This directly?
RowValue rowValueItems=JSSS. Deserialize (recValues. Value. The ToString ());

CodePudding user response:

The
reference 4 floor kuaile999 reply:
recValues. Value. The ToString () Value is equal to the above the json string

List> List=JSSS. Deserialize> (json);
It still won't do,

A list of the Count directly returns 0


Impossible
 
string json="[{"rowValue":[{"componentType":"DepartmentField","label":"费用承担部门","extendValue":[{"number":12,"name":"业务四部","id":"104380371"}],"value":"业务四部","key":"DepartmentField-K371IHGJ"},{"componentType":"TextareaField","label":"用途说明","value":"抵押金置换","key":"付款事由"},{"componentType":"DDSelectField","label":"付款币种","extendValue":{"key":"option_0"},"value":"人民币","key":"DDSelectField-K371IHGN"},{"componentType":"MoneyField","label":"付款金额(元)","value":"370000","key":"MoneyField-K371IHGO"}]}]";
List> List=Tool. JsonToT> (json);
List. The Count. The ToString ();//=& gt; 1




reference 5 floor kuaile999 reply:
oh, excuse me remove [{" rowValue ": after the entity class definition?

This directly?
RowValue rowValueItems=JSSS. Deserialize (recValues. Value. The ToString ());


 
string json="[{"componentType":"DepartmentField","label":"费用承担部门","extendValue":[{"number":12,"name":"业务四部","id":"104380371"}],"value":"业务四部","key":"DepartmentField-K371IHGJ"},{"componentType":"TextareaField","label":"用途说明","value":"抵押金置换","key":"付款事由"},{"componentType":"DDSelectField","label":"付款币种","extendValue":{"key":"option_0"},"value":"人民币","key":"DDSelectField-K371IHGN"},{"componentType":"MoneyField","label":"付款金额(元)","value":"370000","key":"MoneyField-K371IHGO"}]";
List List=Tool. JsonToT (json);
List. The Count. The ToString ();//=& gt; 4

CodePudding user response:

I am using Newtonsoft. Json class, online, flexible to use, you can have a try,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related