【java 中 json的组装】教程文章相关的互联网学习教程文章

java – Jackson映射:使用不同的属性名称反序列化JSON【代码】

我有一个返回json字符串的服务器:{"pId": "ChIJ2Vn0h5wOlR4RsOSteUYYM6g"}现在,我可以使用jackson将其反序列化为一个名为pId的变量的对象,但我不希望该变量被称为pId,我宁愿将其反序列化为placeId. android java中的当前对象:public class Place {private String pId;}我希望对象看起来像什么:public class Place {private String placeId;}如果我将对象的变量更改为placeId,则jackson将无法反序列化JSON,因为属性名称不再匹配....

java – 如何从REstAssured中的Json数组中获取JSON对象【代码】

任何人都可以帮我解决这个问题: 我是RestAssured的新手,在我们的自动化脚本中处理JSON.我有一个API,其响应是JSONArray,即,[{"id": 1002,"entity": "testcase","fieldName": "TextName","displayName": "Name"}, {"id": 1003,"entity": "testcase","fieldName": "steps","displayName": "TestSteps"}]自动化,验证我需要获取响应.我尝试了下面的一个但没有得到预期的输出String API = "/field/entity/testcase"Response response = ...

java.lang.IllegalArgumentException:类java.text.DecimalFormat声明了多个名为maximumIntegerDigits的JSON字段【代码】

我正在对servlet进行ajax调用.我希望数据从servlet返回到jsp:PrintWriter out = response.getWriter();String isbn = (String) request.getParameter("isbn");BookDetail bd = new BookDetail();if(bd.ISBNFound(isbn)){ArrayList<KitapData> Books = bd.LoadBooksByISBN(isbn);Gson gson = new Gson();String json = gson.toJson(Books);response.setContentType("application/json");System.out.print(json); out.print(js...

java – 使用一个不完全是JSON的主体【代码】

我正在开发基于Jersey REST API的Web应用程序.我正在根据客户端要求(JSON格式的输入参数)开发POST服务,并且工作正常.现在他们想要改变输入格式,如下所示.现在我得到415错误(不支持的媒体类型). 这是旧的JSON格式,它的效果很好:{"weight": 5.0,"length": 1.5,"width": 2.7,"height": 0.7 }这个格式客户端需要发送.{ weight = 12; with = 78; height = 78; length = 5; }这是我的POST服务:@POST @Path("/insert") @Consumes({Media...

java – 从json文件加载spring-boot属性【代码】

是否可以从.json文件加载spring-boot配置而不是.yaml或.properties?从查看文档来看,这不是开箱即用的支持 – 我想知道它是否可能,如果是这样,人们会怎么做呢?解决方法:春季引导方式:@EnableAutoConfiguration @Configuration @PropertySource(value = { "classpath:/properties/config.default.json" }, factory=SpringBootTest.JsonLoader.class ) public class SpringBootTest extends SpringBootServletInitializer {@Beanpu...

java – 无法编写JSON:没有为类org.json.JSONObject找到序列化程序,也没有发现创建BeanSerializer的属性【代码】

我已经将响应设置为JSON但是得到了这个Could not write JSON: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)@RequestMapping(value = "/customerlist", method = RequestMethod.POST) public ResponseGenerator getCustomerList() {ResponseGenerator responseGenerator = new ResponseGene...

java – JSON对象属性名称可以是整数吗?【代码】

我刚刚开始使用一些Jackson JSON数据.这部分给了我麻烦."pointData":{"1":"32.1093904, 66.7065216", "2":"33.1236854, 67.8128443", "3":"32.9524550, 67.0013501" }在我看来,将整数作为属性名称是非法的.它是否正确?解决方法:你是正确的,JSON不能有整数属性名称,因为所有JSON属性名称必须引用,因为它们在上面,使它们成为字符串.请参见此处的流程:http://json.org/ 此外,上面的JSON结构无效,因为它以属性名称开头,但没有该属性属...

如何将Java POJO转换为JSON字符串?【代码】

我有一个POJO为我设定值,pojo是:public class CreateRequisitionRO extends AbstractPortfolioSpecificRO {private static final long serialVersionUID = 2418929142185068821L;private BigDecimal transSrlNo;private String transCode;private InflowOutflow inflowOutflow;public BigDecimal getTransSrlNo() {return transSrlNo;}public void setTransSrlNo(BigDecimal transSrlNo) {this.transSrlNo = transSrlNo;}public I...

Caused by: java.util.ConcurrentModificationException: null fastjson

错误信息:Caused by: java.util.ConcurrentModificationException: null at java.util.HashMapHashIterator.nextNode(HashMap.java:1442) [na:1.8.0171]atjava.util.HashMapHashIterator.nextNode(HashMap.java:1442) ~[na:1.8.0_171]at java.util.HashMapHashIterator.nextNode(HashMap.java:1442) [na:1.8.01?71]atjava.util.HashMapEntryIterator.next(HashMap.java:1476) ~[na:1.8.0_171] at java.util.HashMap$EntryIterator...

java – 当不同实体类型的ID重叠时,是否可以使用ObjectIdGenerators.PropertyGenerator来使用@JsonIdentityInfo?【代码】

当来自不同实体类型的ID重叠时,是否可以使用ObjectIdGenerators.PropertyGenerator来使用@JsonIdentityInfo? 假设我有以下XML并希望用Jackson 2.x反序列化它:<foo><id>3</id><name>Peter</name><bar><id>3</id><kind>dog</kind><!--belongsTo>3</belongsTo--></bar> </foo>我用@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property =“id”)注释了Foo和Bar类. 反序列化失败了com.fasterxml.jacks...

java – 配置Gson以更改json中的密钥【代码】

我想在我的网络服务中使用Gson,但我观察到Gson在类中返回一个变量的名称作为Json格式的键.例如interface Animal{} class Dog implements Animal{public String name, age;@Overridepublic String toString() {return name+"\t" + age;} }Json对象的对象如下:{"name":"Tommy","age":"12"}现在,我的问题是因为Json中的Key(名称和年龄)依赖于变量的名称,所以如果我的变量名称发生变化,那么key也会发生变化.然后,只要变量名称在Web服务...

java – 解析JSON数据时出现ArrayIndexOutOfBoundsException错误【代码】

我在id [i] = c.getString(TAG_ID)获得ArrayIndexOutOfBoundsException; 这是代码:for (int i = 0; i < 25; i++) {JSONObject c = contacts.getJSONObject(i);id[i] = c.getString(TAG_ID); }我检查过JSON文件包含25个对象.我也尝试过使用i< 10但它仍然会出现同样的错误.解决方法:id应该是一个至少包含25个元素的数组,以避免索引超出范围.String [] id = new String[25];

java – 将HashMap的ArrayList转换为JSON字符串[复制]【代码】

这个问题与以下内容完全相同: > Converting ArrayList to JSONArray 1个我想转换ArrayList< Hashmap< String,String>>到JSONArray.我用了JSONArray array = new JSONArray(array_list);但它不能正常返回["{image=2130837526, category=Chairs, Quantity=1, price=400, name=chair, prodId=34}","{image=2130837566, category=Mirrors, Quantity=1, price=3000, name=La...

java – 当JSON键有短划线时为Gson设置POJO【代码】

JSON字符串是:{"translation": ["some words"],"basic": {"us-phonetic": "'fl?b?ɡ?st?d","phonetic": "'fl?b?ɡ?st?d","uk-phonetic": "'fl?b?ga:stid","explains": ["v. some words","adj. some words"]} }但Java中没有带“ – ”的值.那么如何获得“us-phonetic”?解决方法:创建一个POJO类来表示您的JSON并使用SerializedName注释装饰您的字段. 当JSON字段的名称和java字段的名称不同时,gson使用@SerializedName(“json_name...

Java – Object Mapper – 要列出的数字的JSON数组【代码】

在我的前端,我发送这个JSON:"ids": [ 123421, 15643, 51243], "user": {"name": "John","email": "john@sovfw.com.br" }到我的Spring Endpoint:@PostMapping(value = "/sendToOficial") public ResponseEntity<?> sendToOficial(@RequestBody Map<String, Object> payload) {ObjectMapper mapper = new ObjectMapper(); List<Long> pointsIds = mapper.convertValue( payload.get("pointsIds"), List.class ); UsuarioDTO autor...