Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I need to retrieve the transaction details like id from given json response.

JavaScript
{
  "id": "PAY-85619955UR925572LKJLINZY",
  "create_time": "2013-10-10T10:52:23Z",
  "update_time": "2013-10-10T10:52:59Z",
  "intent": "sale",
  "payer": {
    "payment_method": "paypal",
    "payer_info": {
      "email": "mudit187@gmail.com",
      "first_name": "Sujeet",
      "last_name": "Singh",
      "payer_id": "HCN5UA7K9PPJJ"
    }
  },
  "transactions": [
    {
      "amount": {
        "currency": "USD",
        "total": "2345.00",
        "details": {
          "subtotal": "2345.00"
        }
      },
      "description": "Transaction description.",
      "related_resources": [
        {
          "sale": {
            "id": "57J06778HJ9237740",
            "create_time": "2013-10-10T10:52:23Z",
            "update_time": "2013-10-10T10:52:59Z",
            "amount": {
              "currency": "USD",
              "total": "2345.00"
            },
            "state": "pending",
            "parent_payment": "PAY-85619955UR925572LKJLINZY",
            "links": [
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/57J06778HJ9237740",
                "rel": "self",
                "method": "GET"
              },
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/sale/57J06778HJ9237740/refund",
                "rel": "refund",
                "method": "POST"
              },
              {
                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-85619955UR925572LKJLINZY",
                "rel": "parent_payment",
                "method": "GET"
              }
            ]
          }
        }
      ]
    }
  ],
  "state": "pending",
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-85619955UR925572LKJLINZY",
      "rel": "self",
      "method": "GET"
    }
  ]
}


And this is the string where i am getting json.

String json = (String)CurrContext.Items["ResponseJson"];

Any help will really apreciated.
Thanks
Posted
Updated 10-Oct-13 1:18am
v2

Thank you all. I have solve this myself. And this is the code...

CS:-

CurrContext.Items.Add("ResponseJson", JObject.Parse(executedPayment.ConvertToJson()).ToString(Formatting.Indented));
String json = (String)CurrContext.Items["ResponseJson"];
hdnPassValue.Value = json;
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "initialize();", true);

JQuery:-
function initialize() {
var jsO = $("#<%=hdnPassValue.ClientID%>").val();
var obj = eval('(' + jsO + ')');
var tId=obj.transactions[0].related_resources[0].sale.id;
alert(tId);
}
 
Share this answer
 
Comments
thatraja 12-Oct-13 2:33am    
5! for your solution to your question.
Sujee1 12-Oct-13 2:36am    
Thank you thatraja :-)
You can serialise and de-serialise JSON to programming objects using DataContract serialisation techniques.

You have to construct an appropriate class to de-serialise to. The following topics should help.

http://msdn.microsoft.com/en-us/library/bb412179.aspx[^]

http://msdn.microsoft.com/en-us/library/bb410770.aspx[^]

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900