我在Lumen有一个网络服务。我整合了Swagger for API DOCS。
输入Json
{"teamId" : 169, "teamName" : "lm", "teamDescription" : "lmnshhhdjj
dhhduxuh
dbbduxhehd
dhhdh8xbbbdhe uudbdhue", "nationality" : "AU", "timezone" : "0"}
此处,密钥teamDescription
是一个包含新行字符的字符串。提交请求后,$request->all()
为空。但对于一个普通的字符串,这个问题不存在。
答案 0 :(得分:1)
换行符在JSON中无效。如何构造无效字符串?
看看这个简单的演示,创建一个有效的 JSON编码的数据字符串:
<?php
$input = [
"teamId" => 169,
"teamName" => "lm",
"teamDescription" => "lmnshhhdjj
dhhduxuh
dbbduxhehd
dhhdh8xbbbdhe uudbdhue",
"nationality" => "AU",
"timezone" => "0"
];
var_dump(json_encode($input));
输出结果为:
string(144) "{"teamId":169,"teamName":"lm","teamDescription":"lmnshhhdjj \ndhhduxuh \ndbbduxhehd \ndhhdh8xbbbdhe uudbdhue","nationality":"AU","timezone":"0"}"