我喜欢这样的注册课程
package com.xyz.model;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Register {
private String Name;
private String Email;
private String Password;
// getter and setter
public Register()
{}
}
这是我的服务代码
public String Register(Register reg) {
String url ="someurl" ;
String name = reg.getName();
//same for email and password
JSONObject jsondata = new JSONObject();
jsondata.put("Name", name);
//same for email password
HttpEntity<?> requestEntity = new Connection().getConnection(jsondata
.toString());
//......code for connection to url..
} catch (Exception e) {
System.out.println("failed"+e.getMessage());
}
每次进入catch阻止并显示错误消息
failed Could not read JSON: Can not instantiate value of type [simple type, class com.xyz.model.Register] from JSON integral number; no single-int-arg constructor/factory method; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class com.xyz.model.Register] from JSON integral number; no single-int-arg constructor/factory method.
我做错的任何帮助。