下面是一个简单的JSON,我试图用java创建一个JSONArray。
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=30, blank=True, default='')
academic_grade = models.CharField(choices=GRADE_CHOICES, default='')
Json:
当我尝试[{
"id":"15973726",
"versionNumber":"5",
"referenceNumber":"123",
"specialInstructions":"Testing"
}]
(身体是JSON)时,我会继续JSONArray rows = JSONArray.fromObject(body);
,但显然它确实以A JSONArray text must begin with '[' at character 1
开头。
这在我的应用程序中工作正常,直到最近的升级需要我在我的[
中将我的java版本从1.6
更改为1.8
。除此之外,没有做出重大改变。所以不确定为什么它不再起作用。
pom.xml
Java:
@SuppressWarnings(
{"rawtypes", "unchecked"})
@RequestMapping(value = "/save", method = RequestMethod.POST)
public
@ResponseBody
String save(@RequestBody String body, HttpServletRequest request, HttpServletResponse response) {
String errorMessage = "";
try {
System.out.println(body);
JSONArray rows = JSONArray.fromObject(new JSONTokener(body));
System.out.println(rows);
return "success";
} catch (Exception e) {
errorMessage = e.getMessage();
}
return errorMessage;
}
"body":
%5B%7B%22id%22%3A%2215973726%22%2C%22
versionNumber%22%3A%225%22%2C%
22%22%2C%22referenceNumber%22%3A%22%22%2C%22
specialInstructions%22%3A%22%22%7D%5D=
POM.xml:
这里有什么问题吗?