JSON.parse()是否有任何字符串长度限制?

时间:2019-04-21 15:37:10

标签: javascript json

我有这个变量(我相信它是json)。然后,我尝试使用JSON.parse()将其传递给对象,该对象只是破坏脚本的执行。考虑到整个链以单引号开头和结尾,因此我删除了单引号,但这并不能解决问题。 在此在线工具(http://json.parser.online.fr/)中,变量正常转换。 有什么建议可以锁定此脚本并阻止将变量转换为对象?

var obj = JSON.parse('{"settings":{"dates.format":"yyyy-MM-dd","dates.locale":"en_US","social.google.enable":1,"social.twitter.enable":1,"social.facebook.enable":1,"realtime.enable":0,"registration.disable":0,"branding.use_custom_theme":1,"branding.favicon":"favicon.ico","branding.logo_dark":"client\/assets\/images\/logo-dark.png","branding.logo_light":"client\/assets\/images\/logo-light.png","i18n.default_localization":"english","i18n.enable":1,"logging.sentry_public":null,"realtime.pusher_key":null,"billing.enable":0,"billing.paypal_test_mode":1,"billing.stripe_test_mode":1,"billing.stripe.enable":0,"billing.paypal.enable":0,"billing.accepted_cards":"[\"visa\",\"mastercard\",\"american-express\",\"discover\"]","homepage.type":"default","homepage.value":"","cache.report_minutes":"60","cache.homepage_days":1,"automation.artist_interval":"7","artist_provider":"Local","album_provider":"Local","radio_provider":"Spotify","genres_provider":"Local","album_images_provider":"real","artist_images_provider":"real","new_releases_provider":"Local","top_tracks_provider":"Local","top_albums_provider":"Local","search_provider":"Local","audio_search_provider":"local","artist_bio_provider":"wikipedia","youtube.suggested_quality":"default","youtube.region_code":"US","player.default_volume":"30","player.hide_queue":0,"player.hide_video":0,"player.hide_video_button":0,"player.hide_lyrics":0,"player.mobile.auto_open_overlay":1,"player.enable_download":0,"player.sort_method":"external","https.enable_cert_verification":1,"site.force_https":0,"menus":"[{\"name\":\"Primary\",\"position\":\"sidebar-primary\",\"items\":[{\"type\":\"route\",\"order\":1,\"label\":\"Popular Albums\",\"action\":\"popular-albums\",\"icon\":\"album\"},{\"type\":\"route\",\"order\":2,\"label\":\"Popular Genres\",\"action\":\"popular-genres\",\"icon\":\"local-offer\"},{\"type\":\"route\",\"order\":3,\"label\":\"Top 50\",\"action\":\"top-50\",\"icon\":\"trending-up\"},{\"type\":\"route\",\"order\":4,\"label\":\"New Releases\",\"action\":\"new-releases\",\"icon\":\"new-releases\"}]},{\"name\":\"Secondary \",\"position\":\"sidebar-secondary\",\"items\":[{\"type\":\"route\",\"order\":1,\"label\":\"Songs\",\"action\":\"\\\/library\\\/songs\",\"icon\":\"audiotrack\"},{\"type\":\"route\",\"order\":2,\"label\":\"Albums\",\"action\":\"\\\/library\\\/albums\",\"icon\":\"album\"},{\"type\":\"route\",\"order\":3,\"label\":\"Artists\",\"action\":\"\\\/library\\\/artists\",\"icon\":\"mic\"}]},{\"name\":\"Mobile \",\"position\":\"mobile-bottom\",\"items\":[{\"type\":\"route\",\"order\":1,\"label\":\"Genres\",\"action\":\"\\\/popular-genres\",\"icon\":\"local-offer\"},{\"type\":\"route\",\"order\":2,\"label\":\"Top 50\",\"action\":\"\\\/top-50\",\"icon\":\"trending-up\"},{\"type\":\"route\",\"order\":3,\"label\":\"Search\",\"action\":\"\\\/search\",\"icon\":\"search\"},{\"type\":\"route\",\"order\":4,\"label\":\"Your Music\",\"action\":\"\\\/library\",\"icon\":\"library-music\"},{\"type\":\"route\",\"order\":4,\"label\":\"Account\",\"action\":\"\\\/account\\\/settings\",\"icon\":\"person\"}]}]","ads.disable":0,"ads.general_top":"<h1>Aqui Propagandas e Comerciais Para Rentabilizar seu SITE.<\/h1>","ads.general_bottom":"<h2>Aqui Propagandas e Comerciais Para Rentabilizar seu SITE.<\/h2>\n<h3>Aqui Propagandas e Comerciais Para Rentabilizar seu SITE.<\/h3>","billing.stripe_public_key":null,"common.site.demo":false,"branding.site_name":"BeMusic","base_url":"http:\/\/127.0.0.1:9090\/estudio\/temp","version":"2.3.6"},"csrf_token":"aUHW7fN9XnzkS2O866kaKm5SrFeLToGAqadhzs8K","guests_role":{"id":1,"name":"guests","permissions":{"users.view":1,"pages.view":1,"artists.view":1,"albums.view":1,"tracks.view":1,"genres.view":1,"lyrics.view":1,"playlists.view":1},"default":false,"guests":true,"created_at":"2019-04-04 10:15:28","updated_at":"2019-04-04 10:15:28"},"i18n":{"model":{"id":1,"name":"english","created_at":"2019-04-04 10:15:28","updated_at":"2019-04-04 10:15:28"},"lines":{"albums":"albums","Add":"Add","":"","Image":"Image","Name":"Name","Artist":"Artist","Release Date":"Release Date","Popularity":"Popularity","Number of Tracks":"Number of Tracks","Views":"Views","tracks":"tracks","New Track":"New Track","Number":"Number","Artists":"Artists","Duration":"Duration","Nothing To Display.":"Nothing To Display.","No tracks have been attached to this album yet.":"No tracks have been attached to this album yet.","Update":"Update","Create":"Create","Search artists...":"Search artists...","Auto Update":"Auto Update","Yes":"Yes","No":"No","artists":"artists","Number of Albums":"Number of Albums","Page Views":"Page Views","Created At":"Created At","New Album":"New Album","Small Image":"Small Image","Large Image":"Large Image","Genres":"Genres","Add new...":"Add new...","Whether this artist data (bio, discography, images etc.) should be updated periodically.":"Whether this artist data (bio, discography, images etc.) should be updated periodically.","Biography":"Biography","Biography Images":"Biography Images","Separate images with a new line (enter).":"Separate images with a new line (enter).","Update Genre\n        New Genre":"Update Genre\n        New Genre","Update Genre":"Update Genre","New Genre":"New Genre","Upload genre image or enter image url.":"Upload genre image or enter image url.","Close":"Close","Update\n            Create":"Update\n            Create","genres":"genres","Number of Artists":"Number of Artists","Update Lyric\r\n        New Lyric":"Update Lyric\r\n        New Lyric","Update Lyric":"Update Lyric","New Lyric":"New Lyric","Track":"Track","Search tracks...":"Search tracks...","Update\r\n            Create":"Update\r\n            Create","lyrics":"lyrics","Song":"Song","Album":"Album","Last Updated":"Last Updated","playlists":"playlists","Owner":"Owner","Public":"Public","Blocked Artist":"Blocked Artist","Artists that should be blocked on the site (they will not be searchable, indexable, or appear on the site in any other way.":"Artists that should be blocked on the site (they will not be searchable, indexable, or appear on the site in any other way.","+Artist Name":"+Artist Name","Player":"Player","Select streaming method and configure player defaults and interface.":"Select streaming method and configure player defaults and interface.","Streaming Method":"Streaming Method","What method should be used to stream music on the site.":"What method should be used to stream music on the site.","Youtube Api Key":"Youtube Api Key","Suggested Quality":"Suggested Quality","Default":"Default","Small":"Small","Medium":"Medium","Large":"Large","HD720":"HD720","HD1080":"HD1080","Highres":"Highres","What quality should be used for youtube videos.":"What quality should be used for youtube videos.","Youtube Region Code":"Youtube Region Code","For what country should youtube results be returned. US recommended. ISO 3166-1 alpha-2 Code.":"For what country should youtube results be returned. US recommended. ISO 3166-1 alpha-2 Code.","Soundcloud Api Key":"Soundcloud Api Key","Default Player Volume (1 to 100)":"Default Player Volume (1 to 100)","Sort Method":"Sort Method","External Popularity":"External Popularity","Local Views":"Local Views","This will be used to sort artists, albums and tracks across the site.":"This will be used to sort artists, albums and tracks across the site.","Automatically Open Overlay on Mobile":"Automatically Open Overlay on Mobile","Should fullscreen video overlay be opened automatically on mobile when user starts playback.":"Should fullscreen video overlay be opened automatically on mobile when user starts playback.","Enable Download Functionality":"Enable Download Functionality","Only works for custom uploaded tracks.":"Only works for custom uploaded tracks.","Hide Queue":"Hide Queue","Should player queue (right sidebar) be hidden by default.":"Should player queue (right sidebar) be hidden by default.","Hide Video":"Hide Video","Should small video in the bottom right corner be hidden.":"Should small video in the bottom right corner be hidden.","Hide Lyrics Button":"Hide Lyrics Button","Hide \"Lyrics\" button in player controls bar.":"Hide \"Lyrics\" button in player controls bar.","Hide Video Button":"Hide Video Button","Hide video toggle button in player controls bar.":"Hide video toggle button in player controls bar.","Hide Radio Button":"Hide Radio Button","Hide all \"go to radio\" buttons across the site.":"Hide all \"go to radio\" buttons across the site.","Data Providers":"Data Providers","Select and configure providers that will be used to automate the site.":"Select and configure providers that will be used to automate the site.","Information":"Information","Local provider means that only data created manually via admin area will be used. No attempt will be made to fetch it from any 3rd party APIs or sites.":"Local provider means that only data created manually via admin area will be used. No attempt will be made to fetch it from any 3rd party APIs or sites.","Generate Sitemap":"Generate Sitemap","Once generated, sitemap index url will be":"Once generated, sitemap index url will be","Artist Provider":"Artist Provider","Album Provider":"Album Provider","Search Provider":"Search Provider","Genres Provider":"Genres Provider","New Releases Provider":"New Releases Provider","Popular Albums Provider":"Popular Albums Provider","Top 50 Provider":"Top 50 Provider","Artist Biography Provider":"Artist Biography Provider","Wikipedia Language":"Wikipedia Language","ISO 639-1 (two letter) language code.":"ISO 639-1 (two letter) language code.","Spotify ID":"Spotify ID","Spotify Secret":"Spotify Secret","Discogs ID":"Discogs ID","Discogs Secret":"Discogs Secret","Last.fm Api Key":"Last.fm Api Key","Should only be disabled if there are problems with 3rd party data providers.":"Should only be disabled if there are problems with 3rd party data providers.","Update Track\r\n        New Track":"Update Track\r\n        New Track","Update Track":"Update Track","Search albums...":"Search albums...","Duration (ms)":"Duration (ms)","Popularity (1 to 100)":"Popularity (1 to 100)","Youtube ID":"Youtube ID","Soundcloud Url":"Soundcloud Url","Url":"Url","(Optional) Absolute url from where track should be streamed.":"(Optional) Absolute url from where track should be streamed.","Upload":"Upload","Plays":"Plays","Release Date:":"Release Date:","Number of Songs:":"Number of Songs:","Running Time:":"Running Time:","Play":"Play","Pause":"Pause","More...":"More...","Add to Queue":"Add to Queue","Add to Playlist":"Add to Playlist","Save to Your Music":"Save to Your Music","Copy Album Link":"Copy Album Link","Share":"Share","Edit":"Edit","New Releases":"New Releases","No new releases found.":"No new releases found.","Could not find any new releases. Please try again later.":"Could not find any new releases. Please try again later.","Popular Albums":"Popular Albums","No albums found.":"No albums found.","Could not find any popular albums. Please try again later.":"Could not find any popular albums. Please try again later.","Overview":"Overview","Similar Artists":"Similar Artists","About":"About","Popular Songs":"Popular Songs","Show More":"Show More","Show Less":"Show Less","Albums":"Albums","Could not find any similar artists for":"Could not find any similar artists for","Could not find biography for":"Could not find biography for","Go to Artist Radio":"Go to Artist Radio","Copy Artist Link":"Copy Artist Link","Back":"Back","Select":"Select","New Playlist":"New Playlist","Copy":"Copy","via email":"via email","+Email address":"+Email address","(Optional) Email message":"(Optional) Email message","Sharing with:":"Sharing with:","Filter...":"Filter...","Sorted by":"Sorted by","Popular Genres":"Popular Genres","No genres found.":"No genres found.","Could not find any popular genres. Please try again later.":"Could not find any popular genres. Please try again later.","Main site search":"Main site search","Search...":"Search...","Admin Area":"Admin Area","Account Settings":"Account Settings","Logout":"Logout","Login":"Login","Register":"Register","Your Music":"Your Music","Playlists":"Playlists","Lyrics":"Lyrics","Update Playlist":"Update Playlist","Playlist Name":"Playlist Name","Playlist Description":"Playlist Description","Give your playlist a catchy description.":"Give your playlist a catchy description.","Songs":"Songs","By":"By","Follow":"Follow","Unfollow":"Unfollow","Delete":"Delete","Make Public":"Make Public","Make Private":"Make Private","Copy Link":"Copy Link","Go to Track Radio":"Go to Track Radio","Remove from Queue":"Remove from Queue","Remove from Playlist":"Remove from Playlist","Remove from Your Music":"Remove from Your Music","Show Lyrics":"Show Lyrics","Copy Track Link":"Copy Track Link","Download":"Download","Radio":"Radio","Search results for":"Search results for","Top Results":"Top Results","Users":"Users","No results for":"No results for","Please check your spelling or try using different keywords.":"Please check your spelling or try using different keywords.","Search":"Search","Find artists, albums, songs, playlists and more.":"Find artists, albums, songs, playlists and more.","View All Results...":"View All Results...","Followers":"Followers","No results found.":"No results found.","Top 50":"Top 50","No charts found.":"No charts found.","Could not find charts. Please try again later.":"Could not find charts. Please try again later.","Duration:":"Duration:","Featured in":"Featured in","Date Added":"Date Added","Artist Name":"Artist Name","Nothing to display.":"Nothing to display.","You have not added any albums to your library yet.":"You have not added any albums to your library yet.","Number of Songs":"Number of Songs","You have not added any artists to your library yet.":"You have not added any artists to your library yet.","Album Name":"Album Name","You have not added any songs to your library yet.":"You have not added any songs to your library yet.","Public Playlists":"Public Playlists","Following":"Following","Seems like this user has not created any playlists yet.":"Seems like this user has not created any playlists yet.","Seems like this user is not following anyone yet.":"Seems like this user is not following anyone yet.","Seems like no one is following this user yet.":"Seems like no one is following this user yet.","You have already created a playlist with this name.":"You have already created a playlist with this name.","auth.failed":"These credentials do not match our records.","auth.throttle":"Too many login attempts. Please try again in :seconds seconds.","pagination.previous":"&laquo; Previous","pagination.next":"Next &raquo;","passwords.password":"Passwords must be at least six characters and match the confirmation.","passwords.reset":"Your password has been reset!","passwords.sent":"We have e-mailed your password reset link!","passwords.token":"This password reset token is invalid.","passwords.user":"We cant find a user with that e-mail address.","validation.accepted":"The :attribute must be accepted.","validation.active_url":"The :attribute is not a valid URL.","validation.after":"The :attribute must be a date after :date.","validation.after_or_equal":"The :attribute must be a date after or equal to :date.","validation.alpha":"The :attribute may only contain letters.","validation.alpha_dash":"The :attribute may only contain letters, numbers, and dashes.","validation.alpha_num":"The :attribute may only contain letters and numbers.","validation.array":"The :attribute must be an array.","validation.before":"The :attribute must be a date before :date.","validation.before_or_equal":"The :attribute must be a date before or equal to :date.","validation.between.numeric":"The :attribute must be between :min and :max.","validation.between.file":"The :attribute must be between :min and :max kilobytes.","validation.between.string":"The :attribute must be between :min and :max characters.","validation.between.array":"The :attribute must have between :min and :max items.","validation.boolean":"The :attribute field must be true or false.","validation.confirmed":"The :attribute confirmation does not match.","validation.date":"The :attribute is not a valid date.","validation.date_format":"The :attribute does not match the format :format.","validation.different":"The :attribute and :other must be different.","validation.digits":"The :attribute must be :digits digits.","validation.digits_between":"The :attribute must be between :min and :max digits.","validation.dimensions":"The :attribute has invalid image dimensions.","validation.distinct":"The :attribute field has a duplicate value.","validation.email":"The :attribute must be a valid email address.","validation.exists":"The selected :attribute is invalid.","validation.file":"The :attribute must be a file.","validation.filled":"The :attribute field must have a value.","validation.image":"The :attribute must be an image.","validation.in":"The selected :attribute is invalid.","validation.in_array":"The :attribute field does not exist in :other.","validation.integer":"The :attribute must be an integer.","validation.ip":"The :attribute must be a valid IP address.","validation.ipv4":"The :attribute must be a valid IPv4 address.","validation.ipv6":"The :attribute must be a valid IPv6 address.","validation.json":"The :attribute must be a valid JSON string.","validation.max.numeric":"The :attribute may not be greater than :max.","validation.max.file":"The :attribute may not be greater than :max kilobytes.","validation.max.string":"The :attribute may not be greater than :max characters.","validation.max.array":"The :attribute may not have more than :max items.","validation.mimes":"The :attribute must be a file of type: :values.","validation.mimetypes":"The :attribute must be a file of type: :values.","validation.min.numeric":"The :attribute must be at least :min.","validation.min.file":"The :attribute must be at least :min kilobytes.","validation.min.string":"The :attribute must be at least :min characters.","validation.min.array":"The :attribute must have at least :min items.","validation.not_in":"The selected :attribute is invalid.","validation.numeric":"The :attribute must be a number.","validation.present":"The :attribute field must be present.","validation.regex":"The :attribute format is invalid.","validation.required":"The :attribute field is required.","validation.required_if":"The :attribute field is required when :other is :value.","validation.required_unless":"The :attribute field is required unless :other is in :values.","validation.required_with":"The :attribute field is required when :values is present.","validation.required_with_all":"The :attribute field is required when :values is present.","validation.required_without":"The :attribute field is required when :values is not present.","validation.required_without_all":"The :attribute field is required when none of :values are present.","validation.same":"The :attribute and :other must match.","validation.size.numeric":"The :attribute must be :size.","validation.size.file":"The :attribute must be :size kilobytes.","validation.size.string":"The :attribute must be :size characters.","validation.size.array":"The :attribute must contain :size items.","validation.string":"The :attribute must be a string.","validation.timezone":"The :attribute must be a valid zone.","validation.unique":"The :attribute has already been taken.","validation.uploaded":"The :attribute failed to upload.","validation.url":"The :attribute format is invalid.","These credentials do not match our records.":"These credentials do not match our records.","Too many login attempts. Please try again in :seconds seconds.":"Too many login attempts. Please try again in :seconds seconds.","&laquo; Previous":"&laquo; Previous","Next &raquo;":"Next &raquo;","Passwords must be at least six characters and match the confirmation.":"Passwords must be at least six characters and match the confirmation.","Your password has been reset!":"Your password has been reset!","We have e-mailed your password reset link!":"We have e-mailed your password reset link!","This password reset token is invalid.":"This password reset token is invalid.","We cant find a user with that e-mail address.":"We cant find a user with that e-mail address.","The :attribute must be accepted.":"The :attribute must be accepted.","The :attribute is not a valid URL.":"The :attribute is not a valid URL.","The :attribute must be a date after :date.":"The :attribute must be a date after :date.","The :attribute must be a date after or equal to :date.":"The :attribute must be a date after or equal to :date.","The :attribute may only contain letters.":"The :attribute may only contain letters.","The :attribute may only contain letters, numbers, and dashes.":"The :attribute may only contain letters, numbers, and dashes.","The :attribute may only contain letters and numbers.":"The :attribute may only contain letters and numbers.","The :attribute must be an array.":"The :attribute must be an array.","The :attribute must be a date before :date.":"The :attribute must be a date before :date.","The :attribute must be a date before or equal to :date.":"The :attribute must be a date before or equal to :date.","The :attribute must be between :min and :max.":"The :attribute must be between :min and :max.","The :attribute must be between :min and :max kilobytes.":"The :attribute must be between :min and :max kilobytes.","The :attribute must be between :min and :max characters.":"The :attribute must be between :min and :max characters.","The :attribute must have between :min and :max items.":"The :attribute must have between :min and :max items.","The :attribute field must be true or false.":"The :attribute field must be true or false.","The :attribute confirmation does not match.":"The :attribute confirmation does not match.","The :attribute is not a valid date.":"The :attribute is not a valid date.","The :attribute does not match the format :format.":"The :attribute does not match the format :format.","The :attribute and :other must be different.":"The :attribute and :other must be different.","The :attribute must be :digits digits.":"The :attribute must be :digits digits.","The :attribute must be between :min and :max digits.":"The :attribute must be between :min and :max digits.","The :attribute has invalid image dimensions.":"The :attribute has invalid image dimensions.","The :attribute field has a duplicate value.":"The :attribute field has a duplicate value.","The :attribute must be a valid email address.":"The :attribute must be a valid email address.","The selected :attribute is invalid.":"The selected :attribute is invalid.","The :attribute must be a file.":"The :attribute must be a file.","The :attribute field must have a value.":"The :attribute field must have a value.","The :attribute must be an image.":"The :attribute must be an image.","The :attribute field does not exist in :other.":"The :attribute field does not exist in :other.","The :attribute must be an integer.":"The :attribute must be an integer.","The :attribute must be a valid IP address.":"The :attribute must be a valid IP address.","The :attribute must be a valid IPv4 address.":"The :attribute must be a valid IPv4 address.","The :attribute must be a valid IPv6 address.":"The :attribute must be a valid IPv6 address.","The :attribute must be a valid JSON string.":"The :attribute must be a valid JSON string.","The :attribute may not be greater than :max.":"The :attribute may not be greater than :max.","The :attribute may not be greater than :max kilobytes.":"The :attribute may not be greater than :max kilobytes.","The :attribute may not be greater than :max characters.":"The :attribute may not be greater than :max characters.","The :attribute may not have more than :max items.":"The :attribute may not have more than :max items.","The :attribute must be a file of type: :values.":"The :attribute must be a file of type: :values.","The :attribute must be at least :min.":"The :attribute must be at least :min.","The :attribute must be at least :min kilobytes.":"The :attribute must be at least :min kilobytes.","The :attribute must be at least :min characters.":"The :attribute must be at least :min characters.","The :attribute must have at least :min items.":"The :attribute must have at least :min items.","The :attribute must be a number.":"The :attribute must be a number.","The :attribute field must be present.":"The :attribute field must be present.","The :attribute format is invalid.":"The :attribute format is invalid.","The :attribute field is required.":"The :attribute field is required.","The :attribute field is required when :other is :value.":"The :attribute field is required when :other is :value.","The :attribute field is required unless :other is in :values.":"The :attribute field is required unless :other is in :values.","The :attribute field is required when :values is present.":"The :attribute field is required when :values is present.","The :attribute field is required when :values is not present.":"The :attribute field is required when :values is not present.","The :attribute field is required when none of :values are present.":"The :attribute field is required when none of :values are present.","The :attribute and :other must match.":"The :attribute and :other must match.","The :attribute must be :size.":"The :attribute must be :size.","The :attribute must be :size kilobytes.":"The :attribute must be :size kilobytes.","The :attribute must be :size characters.":"The :attribute must be :size characters.","The :attribute must contain :size items.":"The :attribute must contain :size items.","The :attribute must be a string.":"The :attribute must be a string.","The :attribute must be a valid zone.":"The :attribute must be a valid zone.","The :attribute has already been taken.":"The :attribute has already been taken.","The :attribute failed to upload.":"The :attribute failed to upload.","The :attribute is not correct.":"The :attribute is not correct."}},"user":{"id":1,"username":"Marco Andre","first_name":null,"last_name":null,"avatar_url":null,"gender":null,"permissions":{"admin":1,"superAdmin":1},"email":"professormarco@msn.com","card_brand":null,"card_last_four":null,"created_at":"2019-04-04 10:15:27","updated_at":"2019-04-04 11:38:18","confirmed":1,"confirmation_code":null,"language":"english","country":null,"timezone":null,"avatar":"http:\/\/127.0.0.1:9090\/estudio\/temp\/storage\/avatars\/gKeugKkYPvke8FeIlGt0eVywxpwLuaJNlc0Mhipb.png","stripe_id":null,"available_space":null,"followers_count":0,"display_name":"professormarco","has_password":true,"roles":[],"followed_users":[]},"tracks":[2],"playlists":[]}');
alert(obj.settings.dates.format);

2 个答案:

答案 0 :(得分:1)

我看到两个单独的问题(在下面的@melpomene指出我错过了第一个问题之后!):

以“ var obj =”开头的行格式错误。

请通过将其粘贴到(例如)Visual Studio Code中并将其保存为“ test.js”来进行验证。

您错误地访问了obj的属性。

这里是使用稍微简单一些的JSON文本示例的说明。

对象属性键可能包含“。”用Javascript

您不是在创建您想创建的继承体系,而是在创建8-)

认为您要在c的{​​{1}}子项的b子项中放置某些内容,但实际上您是在{{1 }} a的子级。

看看这个:

b.c

没有a这样的东西,因此您无法读取其属性a={"b.c":10} console.log(a) Result -> {b.c: 10} a.b.c Result -> * Error * cannot read property 'c' of undefined

相反,您必须阅读以下内容:

a.b

JSON不允许您以尝试的方式设置子项

您要达到的极限不是长度极限,而是表现力。您无法通过这种方式直接设置属性c及其子项a["b.c"] Result -> 10

dates

按如下所示重新构建JSON文本:

  

{“设置”:{“日期”:{“格式”:“ yyyy-MM-dd”,“语言环境”:“ en_US” .....}}}

或者,如果那样做太多,并且您完全控制了从format读取的软件,则可以保持JSON不变,而是着重读取此处的项目:

  

警报(obj.settings [“ dates.format”])

,甚至为了使其在阅读时对自己的未来更加明显,请始终使用{ "settings": { "dates.format": "xxx" }} 表示法。这是Python中使用的格式,也可以在Javascript中使用:

  

提醒(obj [“ settings”] [“ dates.format”])

答案 1 :(得分:-1)

let obj = {
    name: "Mark",
    surname: "Minerov"
};

let object = JSON.stringify(obj);
console.log(object); // {"name":"Mark","surname":"Minerov"}

let parsedObject = JSON.parse(object);
console.log(parsedObject);  //normal object

尝试一下,我认为它将为您提供帮助。