简体   繁体   中英

How to parse this json data in jquery

My json date in attribute need to get on click and need to do 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)

    });

Need to get values.Tried in different ways Am getting if json content is proper, i need to over come even json content is not proper. help to over come it

I would suggest that you make sure, that the API returns a valid JSON. Doing some replacements on the current string will end up in a mess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM