I ran two parts of javascript codes in the JS online platform: Link to the site
pets = '{'pet_names':[{"name":"jack"},{"name":"john"},{"name":"joe"}]}'; var arr = JSON.parse(pets); alert(arr.pet_names[1].name);
Code with double quotes ("pet_names") will be fine, but with single quotes ("pet_names") will remind you of the error: "Unexpected identifier"
pets = '{"pet_names":[{"name":"jack"},{"name":"john"},{"name":"joe"}]}'; var arr = JSON.parse(pets); alert(arr.pet_names[1].name);
So why is this going to happen?
In JSON, only double quotes are valid.
You can find the standard at JSON.org
, , false null, . .
, .
, ,, ,
pets = '{\'pet_names\':[{"name":"jack"},{"name":"john"},{"name":"joe"}]}';
, json, (SyntaxError: Unexpected token), JSON , , JavaScript, JSON.
Source: https://habr.com/ru/post/1547291/More articles:NLTK - нет модуля с именем corpus - pythonFinding the best match for strings with R - stringBlur SKShapeNode with SKEffectNode - iosHow to determine Unicode version in PHP and PCRE? - phpangular-bootstrap accordion binding question - javascriptЯвляются ли переменные окружающей среды Heroku безопасным способом хранения конфиденциальных данных? - rubyHow to write Unit Test for IValidatableObject - unit-testingCoq tactics to ensure equal equality? - coqWhy does DataOutputStream not generate the warning "Resource leak error: stream never closes" - javaHow to specify fonts for text fields using muPDF - c ++All Articles