json文件可以包含多个对象吗?

[英]Can a json file contain more than one object?


Can a json file contain more than one object?

json文件可以包含多个对象吗?

For example, can the content of a json file be two objects as the following?

例如,json文件的内容可以是两个对象,如下所示?

{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"}

Some experienced software engineer said that a json file could only contain one object, although other objects could be nested in the object.

一些有经验的软件工程师说,json文件只能包含一个对象,尽管其他对象可以嵌套在对象中。

Thanks.

谢谢。

2 个解决方案

#1


2  

That doesn't look much like json, but yes, you can totally have an array of objects in json file. Something like this in your case:

这看起来不像json,但是,你可以在json文件中完全拥有一个对象数组。在你的情况下这样的事情:

[{"firstName": "John", "lastName": "Smith"},       
{"firstName": "Jane", "lastName": "Doe"}]

A json file may either contain a single object in (which can be complex, with many nested keys) or an array of such objects. It's either curly braces or square brackets on the outside.

json文件可以包含单个对象(可以是复杂的,具有许多嵌套键)或此类对象的数组。它可以是外侧的花括号或方括号。

#2


0  

Yes.

是。

You can have:

你可以有:

JSONObject = { ObjectOne: { property1: value1 }, ObjectTwo: { property1: value2 }, someProperty: value3, .... }

JSONObject = {ObjectOne:{property1:value1},ObjectTwo:{property1:value2},someProperty:value3,....}

EDIT: You can also have an array of objects if that suits you better.

编辑:如果更适合您,您还可以拥有一系列对象。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/06/29/72016715c846a2b23aefbadee548f7b4.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告