如何在jquery中解析这个json数据

时间:2018-02-28 07:53:36

标签: javascript jquery json

我的json日期属性需要点击,需要做json Parse

<a href="" data-msg="{&quot;countryName&quot;:&quot;Afghanistan&quot;,&quot;cityName&quot;:&quot;Eshkashem&quot;,&quot;supplierType&quot;:&quot;RESTURENT&quot;,&quot;ProductType&quot;:&quot;Dinner&quot;,&quot;SupplierName&quot;:&quot;lassi&quot;,&quot;supplierTypeName&quot;:&quot;RESTURENT&quot;,&quot;products&quot;:{&quot;productName&quot;:&quot;cktessst2&quot;,&quot;productCode&quot;:&quot;JNM5B5MB&quot;,&quot;productDescription&quot;:&quot;<p ><b>Information technology<\/b>&amp;nbsp;(<b>IT<\/b>) is the application of&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer&quot;  title &quot;Computer&quot;>computers<\/a>&amp;nbsp;to store, retrieve, transmit and manipulate&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Data_(computing)&quot;  title &quot;Data (computing)&quot;>data<\/a>,<sup class=&quot;reference&quot; id=&quot;cite_ref-DOP_1-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-DOP-1&quot; >[ ]<\/a><\/sup>&amp;nbsp;or&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information&quot;  title &quot;Information&quot;>information<\/a>, often in the context of a business or other enterprise.<sup class=&quot;reference&quot; id=&quot;cite_ref-2&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-2&quot; >[ ]<\/a><\/sup>&amp;nbsp;IT is considered to be a subset of&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_and_communications_technology&quot;  title &quot;Information and communications technology&quot;>information and communications technology<\/a>&amp;nbsp;(ICT). In 2012, Zuppo proposed an ICT hierarchy where each hierarchy level &amp;quot;contain[s] some degree of commonality in that they are related to technologies that facilitate the transfer of information and various types of electronically mediated communications&amp;quot;.<sup class=&quot;reference&quot; id=&quot;cite_ref-Defining_ICT_in_a_Boundaryless_World:_The_Development_of_a_Working_Hierarchy_3-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-Defining_ICT_in_a_Boundaryless_World:_The_Development_of_a_Working_Hierarchy-3&quot; >[3]<\/a><\/sup><\/p>\n\n <p >The term is commonly used as a&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Synonym&quot;  title &quot;Synonym&quot;>synonym<\/a>&amp;nbsp;for computers and computer networks, but it also encompasses other&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information&quot;  title &quot;Information&quot;>information<\/a>&amp;nbsp;distribution technologies such as television and telephones. Several&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer_industry&quot;  title &quot;Computer industry&quot;>industries<\/a>&amp;nbsp;are associated with information technology, including&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer_hardware&quot;  title &quot;Computer hardware&quot;>computer hardware<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Software&quot;  title &quot;Software&quot;>software<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Electronics&quot;  title &quot;Electronics&quot;>electronics<\/a>,&amp;nbsp;<a class=&quot;mw-redirect&quot; href=&quot;https:\/\/en.wikipedia.org\/wiki\/Semiconductors&quot;  title &quot;Semiconductors&quot;>semiconductors<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Internet&quot;  title &quot;Internet&quot;>internet<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Telecommunications_equipment&quot;  title &quot;Telecommunications equipment&quot;>telecom equipment<\/a>, and&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/E-commerce&quot;  title &quot;E-commerce&quot;>e-commerce<\/a>.<sup class=&quot;reference&quot; id=&quot;cite_ref-DMC_4-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-DMC-4&quot; >[ ]<\/a><\/sup>&amp;nbsp;<sup class=&quot;reference&quot; id=&quot;cite_ref-6&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-6&quot; >[a]<\/a><\/sup><\/p>\n\n <p >Humans have been storing, retrieving, manipulating, and communicating information since the&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Sumer&quot;  title &quot;Sumer&quot;>Sumerians<\/a>&amp;nbsp;in&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Mesopotamia&quot;  title &quot;Mesopotamia&quot;>Mesopotamia<\/a>&amp;nbsp;developed&amp;nbsp;<a class=&quot;mw-redirect&quot; href=&quot;https:\/\/en.wikipedia.org\/wiki\/Cuneiform&quot;  title &quot;Cuneiform&quot;>writing<\/a>&amp;nbsp;in about 3000&amp;nbsp;BC,<sup class=&quot;reference&quot; id=&quot;cite_ref-Butler_7-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-Butler-7&quot; >[ ]<\/a><\/sup>&amp;nbsp;but the term&amp;nbsp;<i>information technology<\/i>&amp;nbsp;in its modern sense first appeared in a 1958 article published in the&amp;nbsp;<i><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Harvard_Business_Review&quot;  title &quot;Harvard Business Review&quot;>Harvard Business Review<\/a><\/i>; authors&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Harold_Leavitt&quot;  title &quot;Harold Leavitt&quot;>Harold J. Leavitt<\/a>&amp;nbsp;and Thomas L. Whisler commented that &amp;quot;the new technology does not yet have a single established name. We shall call it information technology (IT).&amp;quot; Their definition consists of three categories: techniques for processing, the application of statistical and mathematical methods to decision-making, and the simulation of higher-order thinking through computer programs.<sup class=&quot;reference&quot; id=&quot;cite_ref-LeavittWhisler_8-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-LeavittWhisler-8&quot; >[7]<\/a><\/sup><\/p>\n&quot;,&quot;productImage&quot;:&quot;http:\/\/localhost\/nugds2.0\/assets\/mealsvoucher\/a3dcd8615aa646243e97234d4697cf22.jpg&quot;,&quot;productPdfFile&quot;:&quot;&quot;,&quot;productPrice&quot;:23,&quot;apiPrice&quot;:&quot;23&quot;,&quot;discountPrice&quot;:2,&quot;apiDiscountPrice&quot;:&quot;2&quot;,&quot;commissionPrice&quot;:0,&quot;apiCommissionPrice&quot;:0,&quot;productCurrency&quot;:&quot;SGD&quot;,&quot;productValidFrom&quot;:&quot;2018-02-28&quot;,&quot;productValidTo&quot;:&quot;2018-02-28&quot;,&quot;voucherValidTo&quot;:&quot;2018-02-28&quot;,&quot;termsAndConditions&quot;:&quot;<p ><b>Information technology<\/b>&amp;nbsp;(<b>IT<\/b>) is the application of&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer&quot;  title &quot;Computer&quot;>computers<\/a>&amp;nbsp;to store, retrieve, transmit and manipulate&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Data_(computing)&quot;  title &quot;Data (computing)&quot;>data<\/a>,<sup class=&quot;reference&quot; id=&quot;cite_ref-DOP_1-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-DOP-1&quot; >[ ]<\/a><\/sup>&amp;nbsp;or&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information&quot;  title &quot;Information&quot;>information<\/a>, often in the context of a business or other enterprise.<sup class=&quot;reference&quot; id=&quot;cite_ref-2&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-2&quot; >[ ]<\/a><\/sup>&amp;nbsp;IT is considered to be a subset of&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_and_communications_technology&quot;  title &quot;Information and communications technology&quot;>information and communications technology<\/a>&amp;nbsp;(ICT). In 2012, Zuppo proposed an ICT hierarchy where each hierarchy level &amp;quot;contain[s] some degree of commonality in that they are related to technologies that facilitate the transfer of information and various types of electronically mediated communications&amp;quot;.<sup class=&quot;reference&quot; id=&quot;cite_ref-Defining_ICT_in_a_Boundaryless_World:_The_Development_of_a_Working_Hierarchy_3-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-Defining_ICT_in_a_Boundaryless_World:_The_Development_of_a_Working_Hierarchy-3&quot; >[3]<\/a><\/sup><\/p>\n\n <p >The term is commonly used as a&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Synonym&quot;  title &quot;Synonym&quot;>synonym<\/a>&amp;nbsp;for computers and computer networks, but it also encompasses other&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information&quot;  title &quot;Information&quot;>information<\/a>&amp;nbsp;distribution technologies such as television and telephones. Several&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer_industry&quot;  title &quot;Computer industry&quot;>industries<\/a>&amp;nbsp;are associated with information technology, including&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Computer_hardware&quot;  title &quot;Computer hardware&quot;>computer hardware<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Software&quot;  title &quot;Software&quot;>software<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Electronics&quot;  title &quot;Electronics&quot;>electronics<\/a>,&amp;nbsp;<a class=&quot;mw-redirect&quot; href=&quot;https:\/\/en.wikipedia.org\/wiki\/Semiconductors&quot;  title &quot;Semiconductors&quot;>semiconductors<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Internet&quot;  title &quot;Internet&quot;>internet<\/a>,&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Telecommunications_equipment&quot;  title &quot;Telecommunications equipment&quot;>telecom equipment<\/a>, and&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/E-commerce&quot;  title &quot;E-commerce&quot;>e-commerce<\/a>.<sup class=&quot;reference&quot; id=&quot;cite_ref-DMC_4-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-DMC-4&quot; >[ ]<\/a><\/sup>&amp;nbsp;<sup class=&quot;reference&quot; id=&quot;cite_ref-6&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-6&quot; >[a]<\/a><\/sup><\/p>\n\n <p >Humans have been storing, retrieving, manipulating, and communicating information since the&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Sumer&quot;  title &quot;Sumer&quot;>Sumerians<\/a>&amp;nbsp;in&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Mesopotamia&quot;  title &quot;Mesopotamia&quot;>Mesopotamia<\/a>&amp;nbsp;developed&amp;nbsp;<a class=&quot;mw-redirect&quot; href=&quot;https:\/\/en.wikipedia.org\/wiki\/Cuneiform&quot;  title &quot;Cuneiform&quot;>writing<\/a>&amp;nbsp;in about 3000&amp;nbsp;BC,<sup class=&quot;reference&quot; id=&quot;cite_ref-Butler_7-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-Butler-7&quot; >[ ]<\/a><\/sup>&amp;nbsp;but the term&amp;nbsp;<i>information technology<\/i>&amp;nbsp;in its modern sense first appeared in a 1958 article published in the&amp;nbsp;<i><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Harvard_Business_Review&quot;  title &quot;Harvard Business Review&quot;>Harvard Business Review<\/a><\/i>; authors&amp;nbsp;<a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Harold_Leavitt&quot;  title &quot;Harold Leavitt&quot;>Harold J. Leavitt<\/a>&amp;nbsp;and Thomas L. Whisler commented that &amp;quot;the new technology does not yet have a single established name. We shall call it information technology (IT).&amp;quot; Their definition consists of three categories: techniques for processing, the application of statistical and mathematical methods to decision-making, and the simulation of higher-order thinking through computer programs.<sup class=&quot;reference&quot; id=&quot;cite_ref-LeavittWhisler_8-0&quot; ><a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Information_technology#cite_note-LeavittWhisler-8&quot; >[7]<\/a><\/sup><\/p>\n&quot;,&quot;availableQuantity&quot;:&quot;23&quot;,&quot;stockIn&quot;:&quot;23&quot;,&quot;createdBy&quot;:&quot;39&quot;,&quot;productId&quot;:&quot;87&quot;,&quot;countryId&quot;:&quot;1&quot;,&quot;cityId&quot;:&quot;5909&quot;,&quot;supplierTypeId&quot;:&quot;4&quot;,&quot;supplierId&quot;:&quot;7&quot;,&quot;productTypeId&quot;:&quot;6&quot;,&quot;productStatus&quot;:&quot;A&quot;,&quot;productapprovalStatus&quot;:&quot;N&quot;,&quot;redemptionStartFrom&quot;:&quot;2018-02-28&quot;,&quot;appointmentreq&quot;:&quot;I&quot;,&quot;limitTo&quot;:&quot;Male &amp; Female&quot;,&quot;ownCommission&quot;:&quot;2&quot;,&quot;createdDate&quot;:&quot;2018-02-28&quot;,&quot;ApprovalStatus&quot;:&quot;N&quot;},&quot;Branch&quot;:{&quot;branchId&quot;:&quot;21&quot;,&quot;branchName&quot;:&quot;eeeeeeeeeee&quot;,&quot;branchAddress&quot;:&quot;sdfsfsdf&quot;,&quot;contactPerson&quot;:&quot;sdfsdf&quot;,&quot;landmark&quot;:&quot;sdfsdf&quot;,&quot;latitude&quot;:&quot;sddfsdf&quot;,&quot;longitude&quot;:&quot;sdfdsf&quot;,&quot;operatingHours&quot;:&quot;12-32&quot;,&quot;howToGetThere&quot;:&quot;sdfsdf&quot;,&quot;isdCode&quot;:&quot;+65&quot;,&quot;contactNumber&quot;:&quot;213123&quot;},&quot;PriceRange&quot;:[],&quot;productImages&quot;:[&quot;http:\/\/localhost\/nugds2.0\/assets\/mealsvoucher\/7a11ac1712da8dd99af4ca8a952deff9.jpg&quot;,&quot;http:\/\/localhost\/nugds2.0\/assets\/mealsvoucher\/5f8f964a7c4bf5c9b0f8b90916c7ed58.jpg&quot;,&quot;http:\/\/localhost\/nugds2.0\/assets\/mealsvoucher\/0156b88e83e7c2ee3089cda7ab7b4e87.jpg&quot;,&quot;http:\/\/localhost\/nugds2.0\/assets\/mealsvoucher\/8f0fc2a6266d3f978f46770da484e981.jpg&quot;]}" id="productNameEdit">Edit</a>



     tjq(document).on('click','#productNameEdit',function(e){

    var productDetails = JSON.parse(JSON.stringify(tjq(this).attr("data-msg")));
    //var productDetails = JSON.parse(tjq(this).attr("data-msg"));
    alert(productDetails.Branch.branchId)

    });

需要获得价值。以不同的方式结束 如果json内容正确,我需要得到甚至json内容不合适。帮助过来了

1 个答案:

答案 0 :(得分:0)

我建议您确保API返回有效的JSON。对当前字符串进行一些替换将最终陷入混乱。