用js取出数组对象[{"bounds":{"bottom":272,"left":82,"right":160,"top":228},"confidence":0.9984832,"inferenceTime":82.0,"preprocessTime":11.0,"text":"天气","words":"天气"},{"bounds":{"bottom":277,"left":336,"right":417,"top":225},"confidence":0.8993952,"inferenceTime":82.0,"preprocessTime":11.0,"text":"相册","words":"相册"}]的值
时间: 2023-05-19 08:06:28 浏览: 108
可以使用以下代码来取出该数组对象的值:
var arr = [{"bounds":{"bottom":272,"left":82,"right":160,"top":228},"confidence":0.9984832,"inferenceTime":82.0,"preprocessTime":11.0,"text":"天气","words":"天气"},{"bounds":{"bottom":277,"left":336,"right":417,"top":225},"confidence":0.8993952,"inferenceTime":82.0,"preprocessTime":11.0,"text":"相册","words":"相册"}];
console.log(arr[0].bounds); // 输出 {"bottom":272,"left":82,"right":160,"top":228}
console.log(arr[0].confidence); // 输出 0.9984832
console.log(arr[0].text); // 输出 "天气"
console.log(arr[1].bounds); // 输出 {"bottom":277,"left":336,"right":417,"top":225}
console.log(arr[1].confidence); // 输出 0.8993952
console.log(arr[1].text); // 输出 "相册"
相关问题
用js写一个函数,[{"bounds":{"bottom":272,"left":82,"right":160,"top":228},"confidence":0.9984832,"inferenceTime":82.0,"preprocessTime":11.0,"text":"天气","words":"天气"},{"bounds":{"bottom":277,"left":336,"right":417,"top":225},"confidence":0.8993952,"inferenceTime":82.0,"preprocessTime":11.0,"text":"相册","words":"相册"}] 例如传入text的值,返回对应的bounds里的值
可以使用以下函数来实现:
```javascript
function findBounds(text, data) {
const result = data.find(obj => obj.text === text);
return result ? result.bounds : null;
}
```
该函数接受两个参数:text 和 data。text 是要查找的文本,data 是一个包含对象的数组,每个对象都有一个 bounds 属性和一个 text 属性。函数将搜索 data 数组,找到第一个文本值等于 text 的对象,并返回该对象的 bounds。如果找不到匹配的对象,则返回 null。
例如,传入下面的参数:
```javascript
const data = [{"bounds":{"bottom":272,"left":82,"right":160,"top":228},"confidence":0.9984832,"inferenceTime":82.0,"preprocessTime":11.0,"text":"天气","words":"天气"},{"bounds":{"bottom":277,"left":336,"right":417,"top":225},"confidence":0.8993952,"inferenceTime":82.0,"preprocessTime":11.0,"text":"相册","words":"相册"}];
const text = "天气";
const result = findBounds(text, data);
console.log(result); // 输出: {"bottom":272,"left":82,"right":160,"top":228}
```
该函数将返回一个对象,该对象包含 bounds 的值。
注意:这里的代码仅供参考,实际开发中可能需要添加错误处理等功能。
下面这段代码的作用是什么:(defun screenshot-dialog () (let* ((dlg (make-instance 'dialog :title "Screenshot Dialog")) (btn (make-instance 'button :label "Take Screenshot" :action (lambda (btn) (let* ((layout (get-layout)) (view (get-view)) (img (screenshot layout view)) (bmp (make-bitmap img))) (setf (dialog-item-value dlg 'image) bmp)))) (img (make-instance 'image :width 640 :height 480)) (img-item (make-instance 'image-item :image img :alignment :center)) (vbox (make-instance 'vbox :items (list btn img-item)))) (setf (dialog-items dlg) (list vbox)) (show-modal-dialog dlg)))) (defun screenshot (layout view) (let* ((rect (get-view-bounds view)) (img (make-array (list (- (rect:right) (rect:left)) (- (rect:top) (rect:bottom)) 3) :element-type 'unsigned-byte)) (sct (make-screenshot :left (rect:left) :top (rect:bottom) :width (- (rect:right) (rect:left)) :height (- (rect:top) (rect:bottom))))) (with-screenshot sct (with-image img (copy-screenshot-to-image sct img)))))
这段代码定义了两个函数:screenshot-dialog和screenshot。它们的作用是:
1. screenshot-dialog函数创建一个对话框,其中包含一个按钮和一个空的图片框。当用户点击按钮时,该函数会获取当前布局和视图,并使用screenshot函数获取当前视图的屏幕截图,并将其显示在图片框中。
2. screenshot函数接受两个参数:布局和视图。它使用make-screenshot函数创建一个屏幕截图,并使用copy-screenshot-to-image函数将屏幕截图复制到一个图像数组中。最后,它返回一个包含屏幕截图的图像数组。
这段代码的作用是在一个对话框中显示当前视图的屏幕截图,并允许用户保存这个截图。
阅读全文