Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何提取PayPal响应C#_C#_Json_Paypal - Fatal编程技术网

如何提取PayPal响应C#

如何提取PayPal响应C#,c#,json,paypal,C#,Json,Paypal,如何在c#中提取此数据,以获取所需的所有元素: { "id": "PAY-6A414645MC669653MKPB2WCI", "create_time": "2014-07-14T10:03:53Z", "update_time": "2014-07-14T10:05:09Z", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "email": "severiano.testes@gmail.co

如何在c#中提取此数据,以获取所需的所有元素:

{ "id": "PAY-6A414645MC669653MKPB2WCI", "create_time": "2014-07-14T10:03:53Z", "update_time": "2014-07-14T10:05:09Z", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "email": "severiano.testes@gmail.com", "first_name": "tester", "last_name": "tester", "payer_id": "MSQ6UB55W52N6", "shipping_address": { "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "country_code": "GB", "postal_code": "W12 4LQ", "state": "West Midlands" } } }, "transactions": [ { "amount": { "currency": "EUR", "total": "54.00", "details": { "subtotal": "54.00" } }, "description": "Transaction Description", "item_list": { "items": [ { "quantity": "1", "name": "Project Submission (featured)", "price": "54.00", "currency": "EUR", "sku": "64866" } ], "shipping_address": { "recipient_name": "tester tester", "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "country_code": "GB", "postal_code": "W12 4LQ", "state": "West Midlands" } }, "related_resources": [ { "sale": { "id": "4VV61663EL511901P", "create_time": "2014-07-14T10:03:53Z", "update_time": "2014-07-14T10:05:09Z", "amount": { "currency": "EUR", "total": "54.00" }, "state": "pending", "parent_payment": "PAY-6A414645MC669653MKPB2WCI", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4VV61663EL511901P", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4VV61663EL511901P/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6A414645MC669653MKPB2WCI", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "state": "pending", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6A414645MC669653MKPB2WCI", "rel": "self", "method": "GET" } ] }
我已尝试发送到jquery函数,但未成功

我也试过这个:

JObject.Parse(HttpContext.Current.Items["ResponseJson"]).GetValue("id");

这只适用于一个值,而不是我想要的所有值

public class Rootobject
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public string intent { get; set; }
    public Payer payer { get; set; }
    public Transaction[] transactions { get; set; }
    public string state { get; set; }
    public Link1[] links { get; set; }
}

public class Payer
{
    public string payment_method { get; set; }
    public Payer_Info payer_info { get; set; }
}

public class Payer_Info
{
    public string email { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string payer_id { get; set; }
    public Shipping_Address shipping_address { get; set; }
}

public class Shipping_Address
{
    public string line1 { get; set; }
    public string line2 { get; set; }
    public string city { get; set; }
    public string country_code { get; set; }
    public string postal_code { get; set; }
    public string state { get; set; }
}

public class Transaction
{
    public Amount amount { get; set; }
    public string description { get; set; }
    public Item_List item_list { get; set; }
    public Related_Resources[] related_resources { get; set; }
}

public class Amount
{
    public string currency { get; set; }
    public string total { get; set; }
    public Details details { get; set; }
}

public class Details
{
    public string subtotal { get; set; }
}

public class Item_List
{
    public Item[] items { get; set; }
    public Shipping_Address1 shipping_address { get; set; }
}

public class Shipping_Address1
{
    public string recipient_name { get; set; }
    public string line1 { get; set; }
    public string line2 { get; set; }
    public string city { get; set; }
    public string country_code { get; set; }
    public string postal_code { get; set; }
    public string state { get; set; }
}

public class Item
{
    public string quantity { get; set; }
    public string name { get; set; }
    public string price { get; set; }
    public string currency { get; set; }
    public string sku { get; set; }
}

public class Related_Resources
{
    public Sale sale { get; set; }
}

public class Sale
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public Amount1 amount { get; set; }
    public string state { get; set; }
    public string parent_payment { get; set; }
    public Link[] links { get; set; }
}

public class Amount1
{
    public string currency { get; set; }
    public string total { get; set; }
}

public class Link
{
    public string href { get; set; }
    public string rel { get; set; }
    public string method { get; set; }
}

public class Link1
{
    public string href { get; set; }
    public string rel { get; set; }
    public string method { get; set; }
}
然后必须使用Newtonsoft.Json使用
用于
反序列化对象

 var Data = JsonConvert.DeserializeObject<Rootobject>("your Json string");
var Data=JsonConvert.DeserializeObject(“您的Json字符串”);
您可以使用
数据

O/p看起来像


您必须像

public class Rootobject
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public string intent { get; set; }
    public Payer payer { get; set; }
    public Transaction[] transactions { get; set; }
    public string state { get; set; }
    public Link1[] links { get; set; }
}

public class Payer
{
    public string payment_method { get; set; }
    public Payer_Info payer_info { get; set; }
}

public class Payer_Info
{
    public string email { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string payer_id { get; set; }
    public Shipping_Address shipping_address { get; set; }
}

public class Shipping_Address
{
    public string line1 { get; set; }
    public string line2 { get; set; }
    public string city { get; set; }
    public string country_code { get; set; }
    public string postal_code { get; set; }
    public string state { get; set; }
}

public class Transaction
{
    public Amount amount { get; set; }
    public string description { get; set; }
    public Item_List item_list { get; set; }
    public Related_Resources[] related_resources { get; set; }
}

public class Amount
{
    public string currency { get; set; }
    public string total { get; set; }
    public Details details { get; set; }
}

public class Details
{
    public string subtotal { get; set; }
}

public class Item_List
{
    public Item[] items { get; set; }
    public Shipping_Address1 shipping_address { get; set; }
}

public class Shipping_Address1
{
    public string recipient_name { get; set; }
    public string line1 { get; set; }
    public string line2 { get; set; }
    public string city { get; set; }
    public string country_code { get; set; }
    public string postal_code { get; set; }
    public string state { get; set; }
}

public class Item
{
    public string quantity { get; set; }
    public string name { get; set; }
    public string price { get; set; }
    public string currency { get; set; }
    public string sku { get; set; }
}

public class Related_Resources
{
    public Sale sale { get; set; }
}

public class Sale
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public Amount1 amount { get; set; }
    public string state { get; set; }
    public string parent_payment { get; set; }
    public Link[] links { get; set; }
}

public class Amount1
{
    public string currency { get; set; }
    public string total { get; set; }
}

public class Link
{
    public string href { get; set; }
    public string rel { get; set; }
    public string method { get; set; }
}

public class Link1
{
    public string href { get; set; }
    public string rel { get; set; }
    public string method { get; set; }
}
然后必须使用Newtonsoft.Json使用
用于
反序列化对象

 var Data = JsonConvert.DeserializeObject<Rootobject>("your Json string");
var Data=JsonConvert.DeserializeObject(“您的Json字符串”);
您可以使用
数据

O/p看起来像


您只需创建一个映射对象,然后反序列化json即可

public class PaymentResponse
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public string intent {get; set; }
    public Payer payer{get; set; }
}


public class Payer
{

    public string payment_method {get;set;}
    public PayerInfo payer_info {get;set;}
}


public class PayerInfo
{
    public string email { get; set; }
    public string first_name { get; set; }
}
没有时间添加所有值,但如果使用json解析器,则可以更轻松地查看响应。我更喜欢这个

然后用下面的代码反序列化json响应

var paymentResponse = new JavaScriptSerializer().Deserialize<PaymentResponse>(jsonString);
var paymentResponse=new JavaScriptSerializer()。反序列化(jsonString);

您只需创建一个映射对象,然后反序列化json即可

public class PaymentResponse
{
    public string id { get; set; }
    public DateTime create_time { get; set; }
    public DateTime update_time { get; set; }
    public string intent {get; set; }
    public Payer payer{get; set; }
}


public class Payer
{

    public string payment_method {get;set;}
    public PayerInfo payer_info {get;set;}
}


public class PayerInfo
{
    public string email { get; set; }
    public string first_name { get; set; }
}
没有时间添加所有值,但如果使用json解析器,则可以更轻松地查看响应。我更喜欢这个

然后用下面的代码反序列化json响应

var paymentResponse = new JavaScriptSerializer().Deserialize<PaymentResponse>(jsonString);
var paymentResponse=new JavaScriptSerializer()。反序列化(jsonString);