-1

json.netとc#を使用してシリアル化するにはどうすればよいですか? 最善の方法は何ですか?子ノードを追加するには? 次のようなjson文字列を出力します。

{ "OptQty":100,"OptQtySpecified":false, "OptTextList": [{"SiteStockTextNo":1634245835,"DescriptiveText":"TextStyle","DisplayIs":true,"ChangeType":1}], "OptSel" :{"OptRepImageLevel":0,"OptRepImageLevelSpecified":true,"SortOrder":1, "ObjOptInfo":{"ObjOptNo1":0,"ObjOptClaseNm1":"fileds1","ObjOptClaseNm5":""}, "計算" :null, "StockList": [ {"SiteStockNo":1633316906,"Text1":"abcd","Text2":"PK7701","Qty":0,"Price":14500,"SoldOutIs":true}, {"SiteStockNo":1633316907,"Text1":"abcd","Text2":"PK7702","Qty":0,"Price":12500,"SoldOutIs":false}, {"SiteStockNo":1633316908,"Text1":"abcd","Text2":"PK7703","Qty":0,"Price":12500,"SoldOutIs" :false}, {"SiteStockNo":1633316915,"Text1":"abcd","Text2":"PK7711","Qty":0,"Price":2500,"SoldOutIs":false} ] }, "OptAdd ":ヌル }ヌル }ヌル }

4

1 に答える 1

0

最善の方法は、System.Web.Script.Serialization.JavaScriptSerializerを使用することです

A simple Employee object:

public class Employee
{
    public string Name { get; set; }
    public string Age { get; set; }
    public string ID { get; set; }   
}

Adding some instances of them to a List:

Employee oEmployee1 = 
       new Employee{Name="Pini",ID="111", Age="30"};

Employee oEmployee2 = 
      new Employee { Name = "Yaniv", ID = "Cohen", Age = "31" };
Employee oEmployee3 = 
        new Employee { Name = "Yoni", ID = "Biton", Age = "20" };

List<Employee> oList = new List<Employee>() 
{ oEmployee1, oEmployee2, oEmployee3 };

System.Web.Script.Serialization.JavaScriptSerializer oSerializer = 
         new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(oList);
于 2013-05-09T02:35:29.467 に答える