如何将javascript数组放入类对象的arraylist中?
我有以下代码: 广告类别:如何将javascript数组放入类对象的arraylist中?,javascript,java,angularjs,spring,Javascript,Java,Angularjs,Spring,我有以下代码: 广告类别: 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
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解析错误:无法反序列化START\u数组令牌之外的java.lang.String
实例;嵌套异常
如何将$scope.images数组反序列化为图像?您确定
$scope.images
是字符串数组吗?你没有给我们看那部分代码。你所说的“图像”是什么意思。这需要澄清。你是说字节数组吗?或者变量名“images”?是,$scope.images是字符串数组。我指的是变量名图像。这是javascript数组[“”,“”中的$scope.images结构