2014-10-07 84 views
0
public class PurchaseOrder 
{ 
    public IEnumerable<Item> ItemsOrders 
} 

public class Item 
{ 
    public string ItemID 
    public decimal ItemPrice 
} 

当连载它的XML - 获得命名的数组C#json序列化 - 如何将名称添加到列表中的对象?

<PurchaseOrder> 
    <Items> 
     <Item> 
      <ItemID>aaa111</ItemID> 
      <ItemPrice>34.22</ItemPrice> 
     <Item> 
     <Item> 
      <ItemID>bbb222</ItemID> 
      <ItemPrice>2.89</ItemPrice> 
     <Item> 
    </Items> 
</PurchaseOrder> 

但当连载它JSON - 未收到命名的数组

{ 
    "ItemsOrders": [{ 
     "ItemID": "aaa111", 
     "ItemPrice": 34.22 
    }, { 
     "ItemID": "bbb222", 
     "ItemPrice": 2.89 
    }] 
} 

我怎样才能添加名称项目的JSON阵列?

+0

你的数组属性确实有一个名字;它是'ItemsOrders'。 – 2014-10-08 03:03:35

回答

0

我想你可以这样做:

{ 
    "ItemsOrders": 
    [ 
    { 
     Item: 
     { 
     "ItemID": "aaa111", 
     "ItemPrice": 34.22 
     } 
    }, 
    { 
     Item: 
     { 
     "ItemID": "bbb222", 
     "ItemPrice": 2.89 
     } 
    } 
    ] 
} 
+0

如何在代码中做到这一点? – 2014-10-07 19:15:51

相关问题