{"id":943,"date":"2012-01-18T13:30:06","date_gmt":"2012-01-18T10:30:06","guid":{"rendered":"http:\/\/salehalsaffar.com\/blog\/?p=943"},"modified":"2012-01-18T13:30:06","modified_gmt":"2012-01-18T10:30:06","slug":"encode-your-json-data-before-sending-it","status":"publish","type":"post","link":"https:\/\/salehalsaffar.com\/blog\/encode-your-json-data-before-sending-it\/","title":{"rendered":"Encode your JSON data before sending it"},"content":{"rendered":"<p>A problem I was facing recently, that the JSON was being receive properly on Firefox 3.6 my work development machine. Finished the project and deployed it. I haven&#8217;t tested it on other machines, how clever am I?! I opened my laptop to see how it would appear on other browsers, and shockingly, it wasn&#8217;t working at all!<\/p>\n<p>After spending hours trying to locate the line where the error occurs and find out what&#8217;s the problem it turned out that I have to decode the JSON output before sending it. I wasn&#8217;t using any PHP built-in functionality for JSON, that&#8217;s because at work, we are still using PHP4 which has none. I was basically writing the JSON output explicitly. The text output can contain some special characters that need to be encoded and escaped before sending it. After digging around a bit I found out a solution from this <a href=\"http:\/\/techblog.willshouse.com\/2009\/06\/12\/using-json_encode-and-json_decode-in-php4\/\">post<\/a>. Everything is pretty much explained there.<\/p>\n<p>In a nutshell, you&#8217;ll have to use json_encode() to encode the data from an array and then output it. A JSON library is provided along with that post. There is also a decoding function, but I haven&#8217;t use it since I&#8217;m receiving my data on a javascript.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A problem I was facing recently, that the JSON was being receive properly on Firefox 3.6 my work development machine. Finished the project and deployed it. I haven&#8217;t tested it on other machines, how clever am I?! I opened my laptop to see how it would appear on other browsers, and shockingly, it wasn&#8217;t working [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,31],"tags":[146,144,147,148,150,145],"_links":{"self":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts\/943"}],"collection":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/comments?post=943"}],"version-history":[{"count":2,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts\/943\/revisions"}],"predecessor-version":[{"id":946,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts\/943\/revisions\/946"}],"wp:attachment":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/media?parent=943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/categories?post=943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/tags?post=943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}