+ 5
JSON doubt
Hi everyone ,I want to know if someone can help me clearing this doubt , one of my professor's told me that I can write the syntax for Json like this: Data='[{"Name":"Jerry","Age":"21"}]'; Is this correct ? Cause I'm trying to make a Json archive on NetBeans and it keeps showing me that there is an error.
6 Answers
+ 10
This is a json string, not json object
Data='[{"Name":"Jerry","Age":"21"}]';
The correct json object assignment is
var Data= [{Name:"Jerry", Age:21}];
However if you read json from a file, it's in string format
You need to convert it to json object, using JSON.parse method.
var json = '{"result":true, "count":42}'; //json string
obj = JSON.parse(json); // json object
+ 5
For javascript implement, you need to use json object, not json string.
+ 3
json object:
var data={"data one":"data cell","data two":"cell two"};
json string:
var data="{"data one":"data cell","data two":"cell two"};"
conversion to json object:
JSON.parse(data);
conversion to json string:
JSON.stringify(data);
+ 2
Actually json need a proper syntax In which data can be parse.
Correct syntax is:-
var arg= {name: "java", age: 77, city: "Mumbai "};
+ 1
Okay but this needs to be on the JavaScript or in the Json file ?
0
Thank you everyone ,I will try the things that you told me ,I appreciate it