+ 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.

31st Jul 2019, 5:06 AM
Carlos Ramirez
Carlos Ramirez - avatar
6 Respuestas
+ 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
31st Jul 2019, 5:29 AM
Calviղ
Calviղ - avatar
+ 5
For javascript implement, you need to use json object, not json string.
31st Jul 2019, 5:35 AM
Calviղ
Calviղ - avatar
+ 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);
31st Jul 2019, 10:02 AM
Safu8
Safu8 - avatar
+ 2
Actually json need a proper syntax In which data can be parse. Correct syntax is:- var arg= {name: "java", age: 77, city: "Mumbai "};
31st Jul 2019, 8:27 AM
mohit verma
mohit verma - avatar
+ 1
Okay but this needs to be on the JavaScript or in the Json file ?
31st Jul 2019, 5:30 AM
Carlos Ramirez
Carlos Ramirez - avatar
0
Thank you everyone ,I will try the things that you told me ,I appreciate it
31st Jul 2019, 11:05 PM
Carlos Ramirez
Carlos Ramirez - avatar