如何将json转换为c#中的列表并提取相关资源属性中的state属性 [英] how to convert json to a list in c# and extract state property in related resource property
问题描述
{
id:PAY-9FU876104J131673OFCA,
create_time:2014-09-15T12:58:48Z,
update_time:2014-09-15T12:59:08Z,
意图:促销,
付款人:{
payment_method:credit_card,
funding_instruments:[
{
credit_card:{
number:xxxxxxxxxxxx0331,
类型:签证,
expire_month:11,
expire_year:2018年,
first_name:乔,
last_name:购物者,
billing_address: {
line1:52 N Main ST,
city:Johnstown,
country_code:US ,
postal_code:43210,
州:OH
}
}
}
]
},
交易:[
{
金额:{
货币:美元,
总计:7.00 ,
详情:{
运费:1.00,
小计:5.00,
税:1.00
}
},
说明:这是付款交易说明。 ,
item_list:{
items:[
{
数量: 5,
名称:项目名称,
价格:1.00,
货币:USD ,
sku:sku
}
]
},
related_resources:[
{
sale:{
id: 6YF58894BA0554501572E,
create_time:2014-09-15T12:58:48Z,
update_time:2014-09-1 5T12:59:08Z,
金额:{
货币:美元,
总计:7.00
},
州:已完成,
parent_payment:PAY-9FU876104J1316703KQLOFCA ,
链接:[
{
href:https://api.sandbox.paypal.com/v1 / payments / sale / 6YF588er94BA001572E,
:self,
方法:获取
},
{
href:https://api.sandbox.paypal.com/v1/payments/sale/6YF58894BerA001572E/refund,
rel:退款,
方法:POST
},
{
href:https://api.sandbox.paypal.com/v1/payments/payment/PAY-9F45U876104J1316703KQLOFCA,
rel: parent_payment,
方法:获取
}
]
}
}
]
}
],
州:已批准,
链接:[
{
href:https://api.sandbox.paypal.com/v1/payments/付款/ PAY-9FU876104J1316703KQLOFCA,
:自我,
方法:获取
}
]
}
嗨。
您可以使用System.Web.Script.Serialization.JavaScriptSerializer来反序列化JSON。
您将必须创建一些结构化为JSON的类。
希望这会对你有所帮助。 :)
{
"id": "PAY-9FU876104J131673OFCA",
"create_time": "2014-09-15T12:58:48Z",
"update_time": "2014-09-15T12:59:08Z",
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card": {
"number": "xxxxxxxxxxxx0331",
"type": "visa",
"expire_month": 11,
"expire_year": 2018,
"first_name": "Joe",
"last_name": "Shopper",
"billing_address": {
"line1": "52 N Main ST",
"city": "Johnstown",
"country_code": "US",
"postal_code": "43210",
"state": "OH"
}
}
}
]
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "7.00",
"details": {
"shipping": "1.00",
"subtotal": "5.00",
"tax": "1.00"
}
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"quantity": "5",
"name": "Item Name",
"price": "1.00",
"currency": "USD",
"sku": "sku"
}
]
},
"related_resources": [
{
"sale": {
"id": "6YF58894BA0554501572E",
"create_time": "2014-09-15T12:58:48Z",
"update_time": "2014-09-15T12:59:08Z",
"amount": {
"currency": "USD",
"total": "7.00"
},
"state": "completed",
"parent_payment": "PAY-9FU876104J1316703KQLOFCA",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/6YF588er94BA001572E",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/6YF58894BerA001572E/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-9F45U876104J1316703KQLOFCA",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"state": "approved",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-9FU876104J1316703KQLOFCA",
"rel": "self",
"method": "GET"
}
]
}
Hi.
You can use System.Web.Script.Serialization.JavaScriptSerializer to Deserialize the JSON.
You will have to create some classes as structured as the JSON.
Hope this will help you. :)
这篇关于如何将json转换为c#中的列表并提取相关资源属性中的state属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!