0
私はmvc3のWeb APIを使用してWebサービスを作成していますが、これはjsonからデータを取得したいものです。このため、このmvc3のWEB APIを使用してjson配列からデータの配列を取得する方法は?
{"order": {
"locationid": "1",
"deviceidentifier": "XXXXXXXXXXXXXXXXXXXXXXX",
"ordercontactname": "XXXXXXXXXXXXXXXXXXXXXXX",
"ordercontactphone": "XXXXXXXXXXXXXXXXXXXXXXX",
"ordercontactemail": "XXXXXXXXXXXXXXXXXXXXXXX",
"shipaddress1": "17 Brookfield",
"shipaddress2": "Suite 17",
"shipcity": "Irvine",
"shipstate": "CA",
"shipzipcode": "92604",
"shipphonenumber": "9493742114",
"shipemail": "[email protected]",
"shipmethod": "pickup",
"billingfirstname":"Tester",
"billinglastname":"test",
"billingmiddleinitial":"S",
"billingaddress":"field",
"billingcity":"Sample",
"billingstate":"SM",
"billingzipcode":"523201",
"billingphonenumber": "1234567891",
"billingemail": "",
"paytype":"creditcard",
"amount"="10.50",
"acctno"="123456789987",
"exproute"="0114",
"coupon"="X2323",
"notes"="",
"items": [
{"itemid":"1","quantity":"1","price":"2.5","notes":"make it spicy"},
{"itemid":"4","quantity":"2","price":"4.5","notes":""},
{"itemid":"3","quantity":"1","price":"1.5","notes":""}
]
}}
のようなJSONの結果、私はポコクラスを作成していると私はPOCOクラスを使用した注文データを取得するが、私はアイテムデータを取得することができますどのように項目の配列データを取得することはできません
Here is my code
public List<Message> PlaceOrder(PlaceOrder order)
{
// List<PlaceOrder> entities = (List<PlaceOrder>)JavaScriptConvert.DeserializeObject(json, typeof(List<PlaceOrder>));
int PayOrderID = 0;
List<Message> Result;
Result = new List<Message>();
try
{
Order objOrder = new Order();
PayHist objPayhis = new PayHist();
objOrder.LocationId = order.LocationId;
objOrder.DeviceIdentifier = order.DeviceIdentifier;
objOrder.OrderContactName = order.OrderContactName;
objOrder.OrderContactPhone = order.OrderContactPhone;
objOrder.OrderContactEmail = order.OrderContactEmail;
string guid = Guid.NewGuid().ToString();
objOrder.ShipMethod = order.ShipMethod;
objOrder.ShippingDate = Convert.ToDateTime(order.PickupDate);
objOrder.OrderGuid = guid;
entities.AddObject("Orders", objOrder);
entities.SaveChanges();
int orderId = objOrder.OrderId;
PayOrderID = orderId;
objPayhis.OrderId = orderId;
objPayhis.PayType = order.ShipMethod;
objPayhis.Amount = float.Parse(order.Amount);
entities.AddObject("PayHists", objPayhis);
entities.SaveChanges();
JavaScriptSerializer ser = new JavaScriptSerializer();
// Order foo = ser.Deserialize<Order>(json);
Message objMessage = new Message();
objMessage.Messagevalue = "Sucess";
Result.Add(objMessage);
return Result;
}
私を助けてください..
こんにちは応答を与えてくれてありがとう私はこのヘッダーで私は500種類の内部エラーを表示する "アプリケーション/ json"にコンテンツの種類を追加し、ヘッダーを受け入れているヘッダーでこれをテストしました。 – Victor
私の質問は、どのように入れ子配列データを同じ注文IDで私のdbに格納することができますです。 – Victor
私はフィドラーを実行すると500の内部エラーが表示されます。 "{" LocationId ":5、" DeviceIdentifier ":" N "、" OrderContactName ":" Victor "、" OrderContactPhone ":" 1234569874 " "OrderContactEmail": "情報@ ses"、 "ShipMethod": "PickUp"、 "PickupDate": "2011-09-08"、 "Amount": "15.25"、 "MenuItemId": "1_5_9"、 "Quantity" "2_9_8"、 "UnitCost": "2.25_6.65_9.95"、 "オプション": "_ MakeSpicyRaost_"} "それは働いています.. – Victor