javascript - How would I extract this data from JSON and put it in a table -


i want use code, , extract data , add table. got jsfiddle link, code add table not working. not sure, json array ?

http://jsfiddle.net/t7eqg/213/

        $(function(){          var jsonobj = $.parsejson('{"deals":{"items":[{"title":"stripe cashmere blend jumper \u00c2\u00a36 @ george (free c&c)","deal_link":"http:\/\/www.hotukdeals.com\/deals\/stripe-cashmere-blend-jumper-6-george-free-c-c-2390139?aui=1047","mobile_deal_link":"http:\/\/www.hotukdeals.com\/deals\/stripe-cashmere-blend-jumper-6-george-free-c-c-2390139?aui=1047","deal_image":"http:\/\/static.hotukdeals.com\/images\/threads\/2390139_1.jpg","description":"update winter essentials gorgeous stripe cashmere jumper. lovely jumper designed contrast stripe sleeves, awesome update weekly rotation.\n\nbb8 ;)","submit_time":"7 hours, 29 minutes ago","hot_time":"3 hours, 3 minutes ago","poster_name":"bb8","temperature":129.08,"price":"6.00","timestamp":1454709758,"expired":"false","forum":{"name":"deals","url_name":"deals"},"category":{"name":"fashion","url_name":"fashion"},"merchant":{"name":"george (asda george)","url_name":"direct.asda.com-1"},"tags":{"items":[]},"deal_image_highres":"http:\/\/static.hotukdeals.com\/images\/threads\/high-res\/2390139_1.jpg","deal_image_highres_width":372,"deal_image_highres_height":500},{"title":"12 pack polo mint \u00c2\u00a31 instore @ farmfoods","deal_link":"http:\/\/www.hotukdeals.com\/deals\/12-pack-polo-mint-for-1-instore-farmfoods-2389584?aui=1047","mobile_deal_link":"http:\/\/www.hotukdeals.com\/deals\/12-pack-polo-mint-for-1-instore-farmfoods-2389584?aui=1047","deal_image":"http:\/\/static.hotukdeals.com\/images\/threads\/2389584_1.jpg","description":"12 pack polo mint \u00c2\u00a31 instore ","submit_time":"20 hours, 30 minutes ago","hot_time":"3 hours, 21 minutes ago","poster_name":"bulktrans","temperature":117,"price":"1.00","timestamp":1454662886,"expired":"false","forum":{"name":"deals","url_name":"deals"},"category":{"name":"groceries","url_name":"groceries"},"merchant":{"name":"farmfoods","url_name":"farmfoods.co.uk"},"tags":{"items":[{"name":"farmfoods"},{"name":"polo shirt"}]},"deal_image_highres":"http:\/\/static.hotukdeals.com\/images\/threads\/high-res\/2389584_1.jpg","deal_image_highres_width":500,"deal_image_highres_height":375}]},"total_results":1000}');         var html = '<table border="1">';         $.each(jsonobj.deals.items, function(key, value){             html += '<tr>';             html += '<td>' + value.title + '</td>';     html += '<td>' + value.description + '</td>';     html += '<td>' + value.price + '</td>';             html += '</tr>';         });         html += '</table>';          $('div').html(html);     }); 

the problem:

the thing in json breaks parsing is...

...the 2 \n characters in json data!

try this: http://jsfiddle.net/t7eqg/219/

the explanation:

\n parsed javascript @ runtime, resulting in actual line break in json data. means no longer valid code , results in browser error. problem can avoided if use \\n instead, escapes backslash being normal backslash rather part of \n.

the next time parsed, \n form again , make intended line break.

other info:

  • \r same \n (in fact causes line break , should escaped)
  • here two \ns in code: ... weekly rotation.\n\nbb8 ;)"...

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -