boen_robot Posted January 13, 2011 Share Posted January 13, 2011 Hmmmm....I don't really want to see a download box. The json output will be echo'd back to anotherapplication that will parse out the needed info.Either way - the other application will receive the text just fine. Try it in that other application (assuming you have access to it). The download box is only displayed when you manually open that URL, because the browser doesn't know how to visualize JSON. The other app however doesn't need to visualize it - it needs to read it, and it can do that. Link to comment Share on other sites More sharing options...
rayj00 Posted January 13, 2011 Author Share Posted January 13, 2011 Either way - the other application will receive the text just fine. Try it in that other application (assuming you have access to it). The download box is only displayed when you manually open that URL, because the browser doesn't know how to visualize JSON. The other app however doesn't need to visualize it - it needs to read it, and it can do that.I added the "header('Cotent-Type: application/json');" to the beginning of my script.I still see the blue text.Is this something I should be concerned about?Ray Link to comment Share on other sites More sharing options...
thescientist Posted January 13, 2011 Share Posted January 13, 2011 validating your JSON might be helpful for debugging as well.http://www.jsonlint.com Link to comment Share on other sites More sharing options...
boen_robot Posted January 13, 2011 Share Posted January 13, 2011 Opps... my bad... it's header('Content-Type: application/json'); (note the "n" in "Content")BTW JSONLint shows a syntax error in your code about a "{" that follows a "}", i.e. "}{"... you can only send one JSON object at once. If you need to encode several objects into one response, you'll have to first place the objects in an array, and json_encode() the array. Link to comment Share on other sites More sharing options...
rayj00 Posted January 13, 2011 Author Share Posted January 13, 2011 validating your JSON might be helpful for debugging as well.http://www.jsonlint.com The errored line is 146 which is the line where the duplicate json begins.Still confused as to why I am seeing this.And fixing the "Content", I now am seeing the file save box.Ray Link to comment Share on other sites More sharing options...
boen_robot Posted January 13, 2011 Share Posted January 13, 2011 The errored line is 146 which is the line where the duplicate json begins.Still confused as to why I am seeing this.How does your PHP file look in its entirety? Are you sure you aren't outputting the whole thing twice somehow?And fixing the "Content", I now am seeing the file save box.file save box === file download boxYes, this is to be expected. Link to comment Share on other sites More sharing options...
rayj00 Posted January 13, 2011 Author Share Posted January 13, 2011 How does your PHP file look in its entirety? Are you sure you aren't outputting the whole thing twice somehow?file save box === file download boxYes, this is to be expected.Ok, the json now validates with the "header('Content-Type: application/json');" before the echo.(without the header, it does not validate).I still get the save file request. I'm not sure how the app is going to react to this.It may be awhile until I'm at the point to actually test this with the appas I need to do some upfront work as well as figuring out how to parse out what I need, when I need it, where I need it, etc.I will keep you guys informed if you want.Again. Thanks a ton for all the help!Ray Link to comment Share on other sites More sharing options...
boen_robot Posted January 13, 2011 Share Posted January 13, 2011 In what language is the receiving app written?Whatever the case, the way to parse it is sure to be some of the corresponding APIs somewhere on the bottom of JSON's home page. And stop worrying about if it will read it - it WILL. Try it for goodness' sake! Link to comment Share on other sites More sharing options...
rayj00 Posted January 13, 2011 Author Share Posted January 13, 2011 In what language is the receiving app written?Whatever the case, the way to parse it is sure to be some of the corresponding APIs somewhere on the bottom of JSON's home page. And stop worrying about if it will read it - it WILL. Try it for goodness' sake!Actually I will be trying to create an app using Yahoo Connected TV Widget Development Kit.It understands Javascript and XML.It's actually a huge undertaking on my part due to my inexperience with Javascript and XML,but what the heck. I'll give it a try and see how far I can get with it.Ray Link to comment Share on other sites More sharing options...
rayj00 Posted January 18, 2011 Author Share Posted January 18, 2011 Actually I will be trying to create an app using Yahoo Connected TV Widget Development Kit.It understands Javascript and XML.It's actually a huge undertaking on my part due to my inexperience with Javascript and XML,but what the heck. I'll give it a try and see how far I can get with it.RaySo what do you do when you do a query for XML, convert it to JSON and when you validate it,there are errors? One error showed an extra double quote mark.Thanks,Ray Link to comment Share on other sites More sharing options...
justsomeguy Posted January 18, 2011 Share Posted January 18, 2011 If the JSON structure is not valid then the code which generates it is not correct. Link to comment Share on other sites More sharing options...
rayj00 Posted January 18, 2011 Author Share Posted January 18, 2011 So what do you do when you do a query for XML, convert it to JSON and when you validate it,there are errors? One error showed an extra double quote mark.Thanks,RayHere is the error JSON:{"id":"40","name":""Liberals Only" Political Chat Room",Notice 2 sets of quotesRay Link to comment Share on other sites More sharing options...
ShadowMage Posted January 18, 2011 Share Posted January 18, 2011 Here is the error JSON:{"id":"40","name":""Liberals Only" Political Chat Room",Notice 2 sets of quotesYeah, the quotes around "Liberals Only" need to be escaped. How are you converting your XML to JSON? Link to comment Share on other sites More sharing options...
rayj00 Posted January 19, 2011 Author Share Posted January 19, 2011 Yeah, the quotes around "Liberals Only" need to be escaped. How are you converting your XML to JSON?I use: echo json_encode($xml); Link to comment Share on other sites More sharing options...
justsomeguy Posted January 19, 2011 Share Posted January 19, 2011 Do you have a custom version of that function or are you using the built-in one? Link to comment Share on other sites More sharing options...
rayj00 Posted January 19, 2011 Author Share Posted January 19, 2011 Do you have a custom version of that function or are you using the built-in one?I am using whatever my web provider is using. PHP version 5.2.12http://novir.us/phpinfo.php Link to comment Share on other sites More sharing options...
justsomeguy Posted January 19, 2011 Share Posted January 19, 2011 It should be handling that stuff automatically. I think we're going in circles, but what is in $xml? I'm wondering if those are actual quotes or if they are entities that get decoded along the way or something and don't get escaped. Link to comment Share on other sites More sharing options...
rayj00 Posted January 20, 2011 Author Share Posted January 20, 2011 It should be handling that stuff automatically. I think we're going in circles, but what is in $xml? I'm wondering if those are actual quotes or if they are entities that get decoded along the way or something and don't get escaped.Here is the entire php script:<?PHP header('Content-Type: application/json'); //$url = 'http://liberalforum.org/liberalforum/xml.php?showtopic'; //$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); $xml = simplexml_load_file(urldecode($_GET['url'])); echo json_encode($xml);?> Link to comment Share on other sites More sharing options...
rayj00 Posted January 20, 2011 Author Share Posted January 20, 2011 Here is the entire php script:<?PHP header('Content-Type: application/json'); //$url = 'http://liberalforum.org/liberalforum/xml.php?showtopic'; //$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA); $xml = simplexml_load_file(urldecode($_GET['url'])); echo json_encode($xml);?> You still with me justsomeguy? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 20, 2011 Share Posted January 20, 2011 According to the XML output at the commented URL, it is using " for the quotes. I'm not sure why those are automatically being replaced with regular quotes, or why json_encode would not escape the quotes. Link to comment Share on other sites More sharing options...
boen_robot Posted January 20, 2011 Share Posted January 20, 2011 Are you reading the file or the text output again?When the dialog box appears, you must save the file and view it with Notepad. Is it all OK at that point?If you're uncommenting the header line to see what's going on, the text will be treated as HTML, at which points escaped quotes will be displayed as is, making you think what you're thinking. Link to comment Share on other sites More sharing options...
rayj00 Posted January 20, 2011 Author Share Posted January 20, 2011 Are you reading the file or the text output again?When the dialog box appears, you must save the file and view it with Notepad. Is it all OK at that point?If you're uncommenting the header line to see what's going on, the text will be treated as HTML, at which points escaped quotes will be displayed as is, making you think what you're thinking.I was away from this problem for a couple days. Now I am back to pulling my hair!!!here is the php:<?PHP$url = 'http://liberalforum.org/liberalforum/xml.php?showtopic';header('Content-Type: application/json');$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);echo json_encode($xml);?> Here is the query: http://novir.us/test.phpHere is what I got back in the file save. I seen nothing in the browser.:<br /><b>Warning</b>: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: http://liberalforum.org/liberalforum/xml.php?showtopic:48: parser error : Input is not proper UTF-8, indicate encoding !Bytes: 0x92 0x53 0x20 0x48 in <b>/hermes/bosweb/web172/b1723/sl.novirusa/public_html/test.php</b> on line <b>6</b><br /><br /><b>Warning</b>: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: <name><![CDATA[What President Obama’S Heal...]]></name> in <b>/hermes/bosweb/web172/b1723/sl.novirusa/public_html/test.php</b> on line <b>6</b><br /><br /><b>Warning</b>: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ^ in <b>/hermes/bosweb/web172/b1723/sl.novirusa/public_html/test.php</b> on line <b>6</b><br />false Link to comment Share on other sites More sharing options...
boen_robot Posted January 20, 2011 Share Posted January 20, 2011 If you try to open up the XML itself in IE, you'll see a similar error message... this time, liberalforum.org is the problem. Contact them or something. Your script should work as soon as you can see their XML in IE with no errors. Link to comment Share on other sites More sharing options...
rayj00 Posted January 20, 2011 Author Share Posted January 20, 2011 If you try to open up the XML itself in IE, you'll see a similar error message... this time, liberalforum.org is the problem. Contact them or something. Your script should work as soon as you can see their XML in IE with no errors.Ok, there is a difference between IE and Firefox. In Firefox I query: http://liberalforum.org/liberalforum/xml.php?showtopic..and I get:<?xml version="1.0" encoding="UTF-8" ?><ipb> <categories> <category> <id>24</id> <name><![CDATA[Main Political Forums]]></name> <url><![CDATA[http://liberalforum.org/liberalforum/xml.php?showforum=24]]></url> <forums> <forum> <id>44</id> I cut off the rest to save size.Now in IE using the same query I get: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. --------------------------------------------------------------------------------An invalid character was found in text content. Error processing resource 'http://liberalforum.org/liberalforum/xml.php?sho... <name><![CDATA[What President Obama This is getting weirder by the minute. Link to comment Share on other sites More sharing options...
boen_robot Posted January 20, 2011 Share Posted January 20, 2011 Firefox's XML error handling is traditionally worse than that of IE (yes, you read this right... IE beats Firefox in some cases, this being one of them).In their headers, they've specified Content-type: text/xml;charset=ISO-8859-1 which is technically a correct thing to do (AFAIK), but they haven't done the same in their XML... the XML says <?xml version="1.0" encoding="UTF-8" ?> which is basically what's causing the problem... they need to choose an encoding and stick with it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.