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.

編輯:如果更適合您,您還可以擁有一系列對象。


注意!

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



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