[
{
"Intent":"what is manufacturer name?",
"Entity":"Name",
"Response":"Test",
"Status":"0",
"Created_Date":"2017-04-04T00:00:00",
"Response_Count":0,
"Response_Count_string":0
},
{
"Intent":"hi",
"Entity":"hi",
"Response":"hiiii",
"Status":"0",
"Created_Date":"2017-03-28T10:22:00",
"Response_Count":0,
"Response_Count_string":0
},
{
"Intent":"how are you?",
"Entity":"are you fine",
"Response":"good!cool",
"Status":"1",
"Created_Date":"2017-03-28T10:22:38",
"Response_Count":0,
"Response_Count_string":0
}
]
答案 0 :(得分:4)
您的data
是字符串化的JSON。你应该只能JSON.parse
它。
像这样:
var data = "[{\"Intent\":\"what is manufacturer name?\",\"Entity\":\"Name\",\"Response\":\"Test\",\"Status\":\"0\",\"Created_Date\":\"2017-04-04T00:00:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"hi\",\"Entity\":\"hi\",\"Response\":\"hiiii\",\"Status\":\"0\",\"Created_Date\":\"2017-03-28T10:22:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"how are you?\",\"Entity\":\"are you fine\",\"Response\":\"good!cool\",\"Status\":\"1\",\"Created_Date\":\"2017-03-28T10:22:38\",\"Response_Count\":0,\"Response_Count_string\":0}]"
var jsondata = JSON.parse(data)
console.log(jsondata[0].Intent)
console.log(jsondata[1].Intent)
console.log(jsondata[2].Intent)
答案 1 :(得分:0)
<!DOCTYPE html>
<html>
<body>
<p id="demo"> </p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = "[{\"Intent\":\"what is manufacturer name?\",\"Entity\":\"Name\",\"Response\":\"Test\",\"Status\":\"0\",\"Created_Date\":\"2017-04-04T00:00:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"hi\",\"Entity\":\"hi\",\"Response\":\"hiiii\",\"Status\":\"0\",\"Created_Date\":\"2017-03-28T10:22:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"how are you?\",\"Entity\":\"are you fine\",\"Response\":\"good!cool\",\"Status\":\"1\",\"Created_Date\":\"2017-03-28T10:22:38\",\"Response_Count\":0,\"Response_Count_string\":0}]";
var res = str.replace("\'", "");
res= JSON.parse(res)
document.getElementById("demo").innerHTML = res[0].Intent;
}
</script>
</body>
</html>
&#13;
答案 2 :(得分:0)
从 JSON字符串中读取数据的方法:
<强> 1。使用Javascript
var jsonStr = "[{\"Intent\":\"what is manufacturer name?\",\"Entity\":\"Name\",\"Response\":\"Test\",\"Status\":\"0\",\"Created_Date\":\"2017-04-04T00:00:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"hi\",\"Entity\":\"hi\",\"Response\":\"hiiii\",\"Status\":\"0\",\"Created_Date\":\"2017-03-28T10:22:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"how are you?\",\"Entity\":\"are you fine\",\"Response\":\"good!cool\",\"Status\":\"1\",\"Created_Date\":\"2017-03-28T10:22:38\",\"Response_Count\":0,\"Response_Count_string\":0}]";
var jsonObj = JSON.parse(jsonStr);
for (var i in jsonObj) {
console.log(jsonObj[i].Intent);
}
&#13;
<强> 2。使用AngularJS
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl',function($scope) {
var jsonStr = "[{\"Intent\":\"what is manufacturer name?\",\"Entity\":\"Name\",\"Response\":\"Test\",\"Status\":\"0\",\"Created_Date\":\"2017-04-04T00:00:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"hi\",\"Entity\":\"hi\",\"Response\":\"hiiii\",\"Status\":\"0\",\"Created_Date\":\"2017-03-28T10:22:00\",\"Response_Count\":0,\"Response_Count_string\":0},{\"Intent\":\"how are you?\",\"Entity\":\"are you fine\",\"Response\":\"good!cool\",\"Status\":\"1\",\"Created_Date\":\"2017-03-28T10:22:38\",\"Response_Count\":0,\"Response_Count_string\":0}]";
$scope.jsonObj = JSON.parse(jsonStr);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div ng-repeat="item in jsonObj">
{{item.Intent}}
</div>
</div>
&#13;
答案 3 :(得分:-1)
您可以尝试类似
的内容{{1}}