[
{
"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
}
]
Asked
Active
Viewed 111 times
0

ThePerplexedOne
- 2,920
- 15
- 30

divya
- 13
- 4
-
2Could you please give a little more insight into your question? What are you asking her? Where do you need to format the JSON data? Where do you want to read JSON data? What code have you already written? – Alok Apr 05 '17 at 08:30
-
1It's not clear to me whether you want to read this data in JavaScript or in C#? – ThePerplexedOne Apr 05 '17 at 08:31
-
If this is question wants a JavaScript answer it is a duplicate and should be marked as such. – evolutionxbox Apr 05 '17 at 08:41
-
2Possible duplicate of [Safely turning a JSON string into an object](http://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object) – evolutionxbox Apr 05 '17 at 08:43
-
1@tanmay Not really, assuming his json is stored as a variable from a response, and isn't actually plaintext with all those nasty looking escape characters. Why would it be hardcoded? – ThePerplexedOne Apr 05 '17 at 09:17
-
@divya why unaccept the answer ? – Debug Diva Aug 18 '17 at 03:15
4 Answers
4
Your data
is a stringified JSON. You should be able to just JSON.parse
it.
Like this:
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)

tanmay
- 7,761
- 2
- 19
- 38
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>

Suresh B
- 1,658
- 1
- 17
- 35
0
Ways to read the data from JSON String :
1. Using 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);
}
2. Using 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);
});
<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>

Debug Diva
- 26,058
- 13
- 70
- 123
-1
You can try something like
var resultStr = "[{\"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}]";
result = JSON.parse(resultStr);
var data = result[0].Intent;

shbht_twr
- 505
- 3
- 14