首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jQuery中处理JSON字符串?

如何在jQuery中处理JSON字符串?
EN

Stack Overflow用户
提问于 2014-02-10 07:16:17
回答 2查看 487关注 0票数 2

我有一个JSON字符串如下所示

代码语言:javascript
复制
    [{"partner-code":"AMEX",
"partner":"American Express",
"issuer":"American Express",
"summary":[],
"description":[],
"url":"http://www.qantas.com.au/fflyer/dyn/partners/card-american-express",
"email":[],
"phone-number":[],
"mediafile":[],
"bonus-offer-summary":"Earn up to 50,000 bonus Points with the Qantas American Express Ultimate Card. Up to 7,500 bonus Points also available on the Qantas American Express Premium and Discovery Cards. Conditions and spend criteria apply.",
"bonus-offer-description":"You could earn up to 50,000 bonus points with the Qantas American Express Ultimate Card when you apply by 31 December 2013, are approved and meet the eligible spend criterias<sup>***</sup>. Also, you could earn up to 30,000 bonus points with the Qantas American Express Premium Card<sup>^^</sup> or up to 7,500 bonus points with the Qantas American Express Discovery Card<sup>**</sup> when you apply, are approved by 31 December 2013 and meet the eligible spend criteria.",
"show-bonus-offer":"",
"card-offerings":[{"card-name":"Qantas American Express Discovery Card",
                    "earning-points":"This credit card automatically earns Qantas Frequent Flyer points",
                    "website":"http://www.americanexpress.com/au/content/frequent-flyer-cards/qantas-discovery-card/?filter=qanseries&bkgd=3&PID=35&BUID=CCG&AFFID=Qantas&CRTV=Earn&PSKU=AQDB&sourcecode=25A996J001&CPID=100036881",
                    "contact-phone-number":"1300 736 978",
                    "usage-type":"Personal",
                    "card-level":"Classic",
                    "card-type-01":"American Express",
                    "annual-fee":"0","opt-in-fee":"0",
                    "supplementary-card-fee":"0",
                    "supplementary-card-fee-descriptor":"annual Card fee per Supplementary Card<sup>~</sup>",
                    "interest-rate":"20.74",
                    "interest-free-period":"Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup>",
                    "earned-area":"<ul>\r\n\t<li>1 point per $1 eligible spend<sup>*</sup></li>\r\n\t<li>1 extra point per $1 spent in Australia on selected Qantas products &amp; services<sup>+</sup></li>\r\n\t<li>Uncapped points earning<sup>^</sup></li>\r\n\t<li>This introductory offer is available to new<sup>**</sup> American Express Cardmembers only.</li>\r\n</ul>\r\n",
                    "other-features":"<ul>\r\n\t<li>Interest rate of 20.74% p.a.<sup>#</sup></li>\r\n\t<li>Annual card fee of $0</li>\r\n\t<li>$0 annual Card fee per Supplementary Card<sup>~</sup></li>\r\n\t<li>Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup></li>\r\n\t<li>5,000 points after $300 spend<sup>**</sup> on purchases in first 3 months of becoming a Cardmember</li>\r\n\t<li>2,500 points after first Card spend<sup>**</sup> in Australia on selected Qantas products &amp; services in Australia<sup>+</sup></li>\r\n\t<li>Introductory offer available to new<sup>**</sup> American Express Cardmembers only</li>\r\n</ul>\r\n"},
                    {"card-name":"Qantas American Express Premium Card",
                    "earning-points":"This credit card automatically earns Qantas Frequent Flyer points",
                    "website":"http://www.americanexpress.com/au/content/frequent-flyer-cards/qantas-premium-card/?filter=qanseries&bkgd=3&PID=35&BUID=CCG&AFFID=Qantas&CRTV=Earn&PSKU=MB9&sourcecode=25A9974001&CPID=100036882",
                    "contact-phone-number":"1800 040 398",
                    "usage-type":"Personal",
                    "card-level":"Gold",
                    "card-type-01":"American Express",
                    "annual-fee":"249","opt-in-fee":"0",
                    "supplementary-card-fee":"0",
                    "interest-rate":"20.74",
                    "cash-advance-rate":"0",
                    "interest-free-period":"Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup>","earned-area":"<ul class=\"noindent\">\r\n\t<li>You can earn 2 points per dollar spent<sup>*</sup>. Click 'View Website' above for further details.</li>\r\n\t<li>Uncapped points earning<sup>^</sup></li>\r\n</ul>\r\n","other-features":"<ul class=\"noindent\">\r\n\t<li>Interest rate of 20.74% p.a.<sup>#</sup></li>\r\n\t<li>Annual card fee of $249</li>\r\n\t<li>$0 annual Card fee per Supplementary Card<sup>~</sup></li>\r\n\t<li>Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup></li>\r\n\t<li>5,000 points after first Card spend<sup>^^</sup> on eligible purchases</li>\r\n\t<li>2,500 points after first Card spend<sup>^^</sup> on selected Qantas products &amp; services in Australia<sup>+</sup></li>\r\n\t<li>22,500 points after $500 spend within the first three months<sup>^^</sup></li>\r\n\t<li>This introductory offer available to new<sup>^^</sup> American Express Cardmembers only.</li>\r\n\t<li>Complimentary Domestic and Overseas Travel Insurance<sup>##</sup> when you pay for travel with your Card</li>\r\n\t<li>2 Qantas Club invitations per year<sup>~~</sup> after your first Card spend on selected Qantas products &amp; services<sup>+</sup> in Australia</li>\r\n</ul>\r\n"},{"card-name":"Qantas American Express Ultimate Card","earning-points":"This credit card automatically earns Qantas Frequent Flyer points","website":"http://www.americanexpress.com/au/content/frequent-flyer-cards/qantas-ultimate/?filter=qanseries",
                    "contact-phone-number":"1300 736 978",
                    "usage-type":"Personal",
                    "card-level":"Platinum",
                    "card-type-01":"American Express",
                    "interest-free-period":"Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup>",
                    "earned-area":"<ul class=\"noindent\">\r\n\t<li>You can earn:</li>\r\n\t<li>3 Qantas points<sup>*</sup> per dollar spent on eligible Card purchases at:\r\n\t<ul type=\"disc\">\r\n\t\t<li>Tens of thousands of restaurants in Australia<sup>$$</sup></li>\r\n\t\t<li>Selected Qantas products and services in Australia<sup>+</sup></li>\r\n\t</ul>\r\n\t</li>\r\n\t<li>2 points per dollar spent* on eligible Card purchases at:\r\n\t<ul type=\"disc\">\r\n\t\t<li>airlines, accommodation, major cruise and tour operators paid directly or through travel agencies<sup>$$</sup></li>\r\n\t\t<li>Spend in foreign currency when overseas and online<sup>$$</sup></li>\r\n\t</ul>\r\n\t</li>\r\n\t<li>1 point per dollar spent* on eligible Card purchases at:\r\n\t<ul type=\"disc\">\r\n\t\t<li>All other providers, excluding those below</li>\r\n\t\t<li>Insurances offered by American Express</li>\r\n\t</ul>\r\n\t</li>\r\n\t<li>0.5 point per dollar spent* on eligible Card purchases at:\r\n\t<ul type=\"disc\">\r\n\t\t<li>Utilities which are gas, water and electricity providers</li>\r\n\t\t<li>Insurance offered by companies other than American Express</li>\r\n\t\t<li>Telecommunication providers which includes goods and services purchased from phone, mobile and internet service providers</li>\r\n\t\t<li>Government bodies including the Australian Taxation Office, Australia Post, federal/state and local government bodies</li>\r\n\t</ul>\r\n\t</li>\r\n</ul>\r\n","other-features":"<ul class=\"noindent\">\r\n\t<li>Interest rate of 20.74% p.a.<sup>#</sup></li>\r\n\t<li>Annual card fee of $450</li>\r\n\t<li>$0 annual Card fee per Supplementary Card<sup>~</sup></li>\r\n\t<li>Up to 44 days interest free on purchases when the closing balance (including any balance transfer or promotional amount) is paid in full by the statement due date<sup>$</sup></li>\r\n\t<li>5,000 points after first Card spend<sup>***</sup> on eligible purchases</li>\r\n\t<li>2,500 points after first Card spend<sup>***</sup> on selected Qantas products &amp; services in Australia<sup>+</sup></li>\r\n\t<li>42,500 points after $500 spend within the first three months<sup>***</sup></li>\r\n\t<li>Introductory offer available to new<sup>***</sup> American Express Cardmembers only</li>\r\n\t<li>1 Complimentary domestic return flight<sup>+++</sup> between selected Australian Capital cities after your first Card spend every year in Australia on selected Qantas products and services<sup>+</sup></li>\r\n\t<li>Complimentary Domestic and Overseas Travel Insurance<sup>##</sup> when you pay for travel with your Card</li>\r\n</ul>\r\n"},
                    {"card-name":"Test Offering - Sarah",
                    "annual-fee":"0",
                    "opt-in-fee":"0",
                    "supplementary-card-fee":"0",
                    "interest-rate":"0",
                    "cash-advance-rate":"0"}
                ]
}]

我想处理这个字符串在客户端在jQuery中,因为我是新的,我没有想法,任何人,请建议最好的想法去做。这基本上是一个卡信息,像这个'N‘卡信息将在服务器回复,我必须在一个页面中显示一个卡片的列表,如果我们点击一个特定的卡,将显示卡的所有细节,并不得不拖放和比较的卡片。

所以我被困在一张清单上。有谁能尽快帮忙吗?

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-10 07:33:15

在用JSON.parse(yourString)解析JSON字符串之后,或者在jQuery $.parseJSON(yourString)的情况下,您可以使用它作为对象。

例如,如果您这样做:

代码语言:javascript
复制
//yourString is the String provided in the question
var jsonObject = JSON.parse(yourString); 
alert(jsonObject.partner);

它将发出警报:

美国运通

票数 1
EN

Stack Overflow用户

发布于 2014-02-10 07:23:17

您可以使用jQuery`s的函数、函数的parseJSON文档将JSON字符串解析为JavaScript对象,搜索示例可以指导您解决问题的方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21671103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档