这里我有一个动态json
data = {
"name": "deltha",
"type": "object",
"important": [
"name",
"id",
"number"
],
"information": {
"place": {
"editable": false,
"visible": true
},
"info": {
"type": "object",
"properties": {
"type": {
"visible": true
}
}
},
"Image": {
"required": [
"name"
],
"type": "object",
"properties": {
"deltha": {
"search": "yes"
}
}
}
}
}
在这里,我试图检查每个嵌套属性是否具有“ required”属性
前
data['information']["Image"]
在上面的对象中,我具有“需要”的属性,并且在该“名称”下 假设像图像一样,我该如何检查每个属性以检查是否有“ required”(如果需要),那么我该如何动态读取该值
答案 0 :(得分:1)
使用 textureImageWidth = 1024
textureImageHeight = 1024
let macPixelFormatString = "ARGB"
var macPixelFormat: UInt32 = 0
for c in macPixelFormatString.utf8 {
macPixelFormat *= 256
macPixelFormat += UInt32(c)
}
let ioSurface = IOSurfaceCreate([kIOSurfaceWidth: textureImageWidth,
kIOSurfaceHeight: textureImageHeight,
kIOSurfaceBytesPerElement: 4,
kIOSurfaceBytesPerRow: textureImageWidth * 4,
kIOSurfaceAllocSize: textureImageWidth * textureImageHeight * 4,
kIOSurfacePixelFormat: macPixelFormat] as CFDictionary)!
IOSurfaceLock(ioSurface, IOSurfaceLockOptions.readOnly, nil)
let test = CIImage(ioSurface: ioSurface)
IOSurfaceUnlock(ioSurface, IOSurfaceLockOptions.readOnly, nil)
检查属性是否存在
hasOwnProperty
答案 1 :(得分:1)
我建议使用递归函数,这是一个有效的示例:stackblitz.com/edit/angular-snucnm
答案 2 :(得分:1)
您可以按以下方式检查该属性的可用性,
if (data.information.Image.required !== undefined) {
console.log('prop is defined')
}