简体   繁体   English

Phonegap IOS应用程序,JSON解析错误?

[英]Phonegap IOS app, JSON parse error?

I am generating a json object from php with json_encode and consume it with JS. 我正在用json_encode从php生成一个json对象,并用JS消费它。 The JSON object is valid, i run it through JSON lint, but I am always getting a parseerror when it is consumed from the php file directly. JSON对象有效,我通过JSON lint运行它,但是当直接从php文件中使用它时,我总是会遇到parseerror。

Now, if i generate a .json file and output the object there no error is raised. 现在,如果我生成一个.json文件并输出该对象,则不会引发任何错误。

Has anyone come across this problem? 有人遇到过这个问题吗? Any thoughts as to why this might be happening? 关于为什么会发生这种情况有任何想法吗?

Thank you. 谢谢。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

Try not passing the JSON object to the JS file but instead echo it out on the php file then tell js in an output function of some sort to pick it up1 尝试不将JSON对象传递给JS文件,而是在php文件中将其回显,然后在某种输出函数中告诉js来将其拾取1

eg echo json_encode // In php file 例如echo json_encode //在php文件中

function(output){ ('some element').html(output); function(output){('some element')。html(output); //output is what is returned from the php file (the json) } //输出是从php文件(json)返回的内容}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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