这是我的JSON数据:
{
"status": "Succeeded",
"recognitionResult": {
"lines": [
{
"boundingBox": [
2,
52,
65,
46,
69,
89,
7,
95
],
"text": "The quick brown fox jumps over the lazy",
}
]
}
我想从这个JSON数据中提取文本。我该怎么做?
答案 0 :(得分:0)
您可以尝试以下方式:
var myJSON = {
"status": "Succeeded",
"recognitionResult": {
"lines": [
{
"boundingBox": [
2,
52,
65,
46,
69,
89,
7,
95
],
"text": "The quick brown fox jumps over the lazy",
}
]
}
}
var text = myJSON.recognitionResult.lines[0].text;
console.log(text)
答案 1 :(得分:0)
var status = myJSON.status;
alert( status );
var text = myJSON.recognitionResult.lines[0].text;
alert( text );
答案 2 :(得分:0)
让代码考虑动态行为总是更好。如果您的lines
数组有多个对象怎么办?因此,我建议在这种情况下使用循环,尽管甚至有一个对象。
var jsonData = {
"status": "Succeeded",
"recognitionResult": {
"lines": [
{
"boundingBox": [
2,
52,
65,
46,
69,
89,
7,
95
],
"text": "The quick brown fox jumps over the lazy"
},
{
"boundingBox": [
2,
52,
65,
95
],
"text": "fox jumps over the lazy"
}
]
}
};
jsonData.recognitionResult.lines.forEach(function(line){
console.log(line.text);
});