使用回车键将 json 发送到 php Web 服务


Sending json with enter key to php web service

我正在为Android应用程序开发PHP网络服务。

在这里我发送 json :

{"company":"wipro","user_id":19,"title":"title_update","from_date":"01-02-2014","to_date":"11-02-2014","additional_notes":"worked with 3 reputed firms"}

这是一个有效的 JSON,但要求是用户可以在additional_notes参数中按"Enter 键",这会使 JSON 无效。有没有办法解决这样的问题?如果无法使用回车键发送 json,那么使用 Xml 是否可以发送 json。

只要我了解您的问题,您就希望发送值包含换行符 (''') 的 additional_notes 键。

例如

{"company":"wipro","user_id":19,"title":"title_update","from_date":"01-02-2014","to_date":"11-02-2014","additional_notes":"worked with 3 reputed firms 'n currently working with abc"}

currently working with abc行是换行符上的文本。

如果您使用文本区域进行additional_notes则它将自动为新行添加"'"字符。添加换行符 (''') 不会使 json 失效。使 json 无效的是当您将additional_notes键的值分解为脚本代码中的下一行时。

您可以创建单个文本行的列表/数组。在将多行文本发送到单行字符串之前解析您的多行文本,在您的服务器上,您需要再次将它们放在一起。然后,您的 json 应如下所示:

{"multi_line_text":["line one","line two","line three"]}

这不是最好的解决方案,但它应该有效