【发布时间】:2012-12-29 04:05:36
【问题描述】:
如何将此处的所有数据包装在一个数组中?这是从网站系统自动生成的,我输入它的应用程序需要将数据放在数组中。 JSON 中有多组数据,这只是大约 5 或 6 个中的 2 个。
collection: {
id: "5096f729e4b02d37bef658f2",
enabled: true,
starred: false,
type: 10,
ordering: 3,
title: "About",
navigationTitle: "About",
urlId: "about",
itemCount: 0,
updatedOn: 1347025745523,
publicCommentCount: 0,
folder: false,
dropdown: false,
tags: [ ],
categories: [ ],
homepage: true,
typeName: "page",
synchronizing: false,
typeLabel: "page",
fullUrl: "/"
},
websiteSettings: {
id: "5096f728e4b02d37bef658e0",
websiteId: "5096f728e4b02d37bef658df",
type: "Business",
subject: "Personal",
country: "US",
state: "NY",
markdownMode: false,
simpleLikingEnabled: true,
commerceEnabled: false,
defaultPostFormat: "%y/%m/%d/%t",
commentLikesAllowed: true,
commentAnonAllowed: true,
commentThreaded: true,
commentApprovalRequired: false,
commentAvatarsOn: true,
commentSortType: 2,
commentFlagThreshold: 0,
commentFlagsAllowed: true,
commentEnableByDefault: true,
commentDisableAfterDaysDefault: 0,
disqusShortname: "username",
homepageTitleFormat: "%s - This is a test",
collectionTitleFormat: "%c — %s - This is a test",
itemTitleFormat: "%i — %s - This is a test",
commentsEnabled: true,
allowSquarespacePromotion: false,
storeSettings: {
storeTitle: "Test",
returnPolicy: null,
termsOfService: null,
privacyPolicy: null,
stockLevelAlertLimit: 5,
useLightCart: false,
stripeConnected: false,
storeState: 3
}
}
【问题讨论】:
-
@Passerby:问题中没有提到 PHP。
-
我们需要更多信息来回答问题。你想做什么。我的意思是,如果您只是想将它包装在一个数组中,只需在开头和结尾添加
[和]——您似乎已经拥有有效的 json 对象 -
对不起。因此,可以通过在 Squarespace 网站平台的页面上附加 ?format=json-pretty 来获得此 JSON 数据。示例:squarespace.com/?format=json-pretty 我需要在我的应用程序中使用 Javascript 或 Jquery 将数据放入数组中,因为该应用程序只识别数组中的数据。
-
所以数据是作为对象属性给出的,其键是“collection”、“website”、“items”等。你想要一个只包含这些键的值的数组吗?跨度>
-
问题是它不是数组数据。它是带有键和值的数据。您当然可以创建一个仅包含值的数组,但是您的应用程序如何知道每个值的含义?您必须对每个数组位置的含义进行硬编码?或者你想要一个对象数组,其中每个对象都包含一个键和值?
标签: javascript jquery arrays json object