从json响应中获取数据。

编程入门 行业动态 更新时间:2024-10-06 18:30:32
本文介绍了从json响应中获取数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我需要从给定的json响应中检索id等事务详细信息。

Hi all, I need to retrieve the transaction details like id from given json response.

{ "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", "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": "api.sandbox.paypal/v1/payments/sale/57J06778HJ9237740", "rel": "self", "method": "GET" }, { "href": "api.sandbox.paypal/v1/payments/sale/57J06778HJ9237740/refund", "rel": "refund", "method": "POST" }, { "href": "api.sandbox.paypal/v1/payments/payment/PAY-85619955UR925572LKJLINZY", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "state": "pending", "links": [ { "href": "api.sandbox.paypal/v1/payments/payment/PAY-85619955UR925572LKJLINZY", "rel": "self", "method": "GET" } ] }

这是我得到json的字符串。 String json =(String )CurrContext.Items [ResponseJson]; 任何帮助都会真正贬值。 谢谢

And this is the string where i am getting json. String json = (String)CurrContext.Items["ResponseJson"]; Any help will really apreciated. Thanks

推荐答案

您可以使用 DataContract 序列化技术将 JSON 序列化和反序列化为编程对象。 你必须构造一个适当的类来反序列化。以下主题应该有所帮助。 http: //msdn.microsoft/en-us/library/bb412179.aspx [ ^ ] msdn.microsoft/en-us/library/bb410770.aspx [ ^ ] msdn.microsoft/en-us/library/system.runtime.serialization.json.datacontractjsonserializer。 aspx [ ^ ] 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. msdn.microsoft/en-us/library/bb412179.aspx[^] msdn.microsoft/en-us/library/bb410770.aspx[^] msdn.microsoft/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[^]

谢谢大家。我自己解决了这个问题。这是代码... 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: - 函数initialize(){ var jsO = 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); } ("#<%=hdnPassValue.ClientID%>").val(); var obj = eval('(' + jsO + ')'); var tId=obj.transactions[0].related_resources[0].sale.id; alert(tId); }

更多推荐

从json响应中获取数据。

本文发布于:2023-11-26 23:10:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!