JSON.parse fails
I'm trying to use the Viper Smart Start plugin which parses a response from a PHP page. Everything works up until the script tries to parse the result from the PHP page and I haven't been able to figure out why it is failing. I know that the openuri is working because I am able to start my car and have confirmed that I do get a result from the PHP page so Im pretty confident its something to do with JSON.parse. Here are a couple of lines from the script:
status = JSON.parse(open(URI("#{self.url}?action=#{viper_command}")).read) ... ... if(status["Return"]["ResponseSummary"]["StatusCode"] == 0)
I put some debug statements right after the call to JSON.parse and the code gets there, but as soon as it tries to access the status object, Siri just hangs and has to be manually stopped since it never reaches request_completed. Whats strange is that I have been able to take some of the code and run it irb and I can see the value of status["Return"]["ResponseSummary"]["StatusCode"]. Any ideas why parsing fails in the script but not in irb?
I would output the response from the php script to the logs and confirm it is valid JSON. You can keep it from hanging by adding a rescue to the JSON.parse line and have it return an error response.
-Pete
Sent from my iPhone
On Dec 29, 2011, at 11:00 AM, jstockton [email protected] wrote:
I'm trying to use the Viper Smart Start plugin which parses a response from a PHP page. Everything works up until the script tries to parse the result from the PHP page and I haven't been able to figure out why it is failing. I know that the openuri is working because I am able to start my car and have confirmed that I do get a result from the PHP page so Im pretty confident its something to do with JSON.parse. Here are a couple of lines from the script:
status = JSON.parse(open(URI("#{self.url}?action=#{viper_command}")).read) ... ... if(status["Return"]["ResponseSummary"]["StatusCode"] == 0)
I put some debug statements right after the call to JSON.parse and the code gets there, but as soon as it tries to access the status object, Siri just hangs and has to be manually stopped since it never reaches request_completed. Whats strange is that I have been able to take some of the code and run it irb and I can see the value of status["Return"]["ResponseSummary"]["StatusCode"]. Any ideas why parsing fails in the script but not in irb?
Reply to this email directly or view it on GitHub: https://github.com/plamoni/SiriProxy/issues/227