gpt4 book ai didi

java - JSON 到 java 的转换

转载 作者:行者123 更新时间:2023-12-01 17:08:04 25 4
gpt4 key购买 nike

我想将以下 JSON 转换为 java Object 。请建议最简单的方法。我不想在转换 JSON 字符串时使用转义字符。

{
"sid": "S-121",
"name": "Sumit",
"address": {
"pin": "560068",
"state": "Karnataka",
"street": {
"stid": "1111",
"landMark": "DX Apartment",
"postOffice": "Bomanhalli"
}
}
}

最佳答案

     Street strt= new Street("1111", "DX Apartment", "Bomanhalli");
Address address= new Address("560068", "Karnataka",strt);
Student st= new Student("S-121","Sumit", address);
ObjectMapper mapper= new ObjectMapper();
String JasonString= mapper.writeValueAsString(st);
System.out.println(JasonString);

Student studnt= mapper.readValue(JasonString, Student.class);
System.out.println(studnt);

关于java - JSON 到 java 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61446591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com