javascript - 如何将 javascript 数组放入类对象的数组列表中?
问题描述
我有以下代码:
广告类:
public class Advertisement {
String name;
String description;
Date date;
String city;
String type;
int rooms;
int surface;
int price;
int userID;
ArrayList<String> images;
int httpStatus;
}
广告弹簧控制器:
@RequestMapping(value = "/post", method = RequestMethod.POST)
public boolean postAds(@RequestBody Advertisement newAd) {
System.out.println(newAd.name+" "+" "+newAd.rooms+" "+newAd.surface+" "+newAd.price+" " + newAd.type+" "+newAd.description+newAd.images);
return true;
}
角度控制器:
$http({
method: 'POST',
url: AppSettings.getApiUrl('/post'),
data: {
name: $scope.form.name,
description: $scope.form.description,
//city: $scope.form.city,
rooms: $scope.form.rooms,
surface: $scope.form.surface,
price: $scope.form.price,
type: $scope.form.selected,
images: $scope.images,
//userId: localStorage.getItem('token'),
}
现在,当我向服务器发出 post 请求时,它会出现以下错误:
JSON 解析错误:无法反序列化
java.lang.String
超出 START_ARRAY 令牌的实例;嵌套异常
我应该如何将 $scope.images 数组反序列化为图像?
解决方案
推荐阅读
- node-red - 配置远程节点红色模块时出错
- c# - “NameOfProperty”不能用作实体类型“NameOfType”的属性,因为它被配置为导航
- javascript - 材质 UI 表。如何将可扩展表与父表对齐
- android - 在 Android 设备上以编程方式获取 CPU 时钟速度?
- c++ - 分配对结构的引用
- asp.net-core - “ProtoCompile”任务无法使用其输入参数初始化
- wordpress - 如何在多个 Wordpress 安装中更改 wp-config.php 中的数据库密码
- github - 在 GitHub 中维护多个不同版本的最佳方式
- java - 没有关系的房间中的一对多关系
- javascript - 您可以将数字填充添加到引导数字输入框中吗?