{"body" : {"data":[{"cust_num": "806200102581556","mob": null,"open_org_num": "806020901"}] }} 转java对象
时间: 2024-03-11 11:42:46 浏览: 101
Cust_Camera_Ocr:通过智能手机摄像头相机和tesseract lib识别Android字符
根据你提供的信息,这是一个JSON格式的数据,可以将其转换为Java对象。在Java中,可以使用第三方库如Jackson或Gson来进行JSON与Java对象之间的转换。以下是使用Jackson库将该JSON数据转换为Java对象的示例代码:
```java
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static void main(String[] args) {
String json = "{\"body\":{\"data\":[{\"cust_num\":\"806200102581556\",\"mob\":null,\"open_org_num\":\"806020901\"}]}}";
try {
ObjectMapper objectMapper = new ObjectMapper();
MyObject myObject = objectMapper.readValue(json, MyObject.class);
System.out.println(myObject);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class MyObject {
private Body body;
public Body getBody() {
return body;
}
public void setBody(Body body) {
this.body = body;
}
@Override
public String toString() {
return "MyObject{" +
"body=" + body +
'}'; }
}
class Body {
private Data[] data;
public Data[] getData() {
return data;
}
public void setData(Data[] data) {
this.data = data;
}
@Override
public String toString() {
return "Body{" +
"data=" + Arrays.toString(data) +
'}';
}
}
class Data {
private String cust_num;
private String mob;
private String open_org_num;
public String getCust_num() {
return cust_num;
}
public void setCust_num(String cust_num) {
this.cust_num = cust_num;
}
public String getMob() {
return mob;
}
public void setMob(String mob) {
this.mob = mob;
}
public String getOpen_org_num() {
return open_org_num;
}
public void setOpen_org_num(String open_org_num) {
this.open_org_num = open_org_num;
}
@Override
public String toString() {
return "Data{" +
"cust_num='" + cust_num + '\'' +
", mob='" + mob + '\'' +
", open_org_num='" + open_org_num + '\'' +
'}';
}
}
```
请注意,上述代码中的`MyObject`、`Body`和`Data`类是根据提供的JSON数据结构定义的。你可以根据实际情况进行调整。
阅读全文