对象列表的 JSON 结构 [英] JSON Structure for List of Objects

查看:60
本文介绍了对象列表的 JSON 结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,JSON 中对象列表的正确结构是什么.

I would like to know, whats the right structure for a list of objects in JSON.

我们使用 JAXB 将 POJO 转换为 JSON.

We are using JAXB to convert the POJO's to JSON.

这是选择,请告诉我什么是正确的.

Here is the choices, Please direct me what is right.

foos: [
             foo:{..},
             foo:{..}
      ]

   foos : [
           {...},
           {...}
          ]

如果第一个结构是正确的,我应该使用什么 JAXB 注释来使结构正确.

If the first structure is right, what is the JAXB annotation I should use to get the structure right.

推荐答案

第一个是无效的语法.普通数组中不能有对象属性.第二个是正确的,尽管它不是 strict JSON.这是一种宽松形式的 JSON,其中省略了字符串键中的引号.

The first one is invalid syntax. You cannot have object properties inside a plain array. The second one is right although it is not strict JSON. It's a relaxed form of JSON wherein quotes in string keys are omitted.

Patrick Hunlock 的本教程,可能有助于了解 JSON 和本网站可能有助于验证 JSON.

This tutorial by Patrick Hunlock, may help to learn about JSON and this site may help to validate JSON.

这篇关于对象列表的 JSON 结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆