Использование переменной в кавычках при парсинге JSON



  • Добрый день. Нужно спарсить две строчки last_modified и setting определенного сайта из этого текста JSON :

    {"account_id_migration_state":2,"account_tracker_service_last_update":"13203762975894958","autocomplete":{"retention_policy_last_version":76},"autofill":{"japan_city_field_migrated_to_street_address":true,"last_version_validated":75,"orphan_rows_removed":true},"browser":{"has_seen_welcome_page":false,"last_google_search_domain_mixing_metrics_time":"13203738000000000","window_placement":{"bottom":718,"left":10,"maximized":false,"right":1060,"top":10,"work_area_bottom":728,"work_area_left":0,"work_area_right":1360,"work_area_top":0}},"countryid_at_install":21077,"data_reduction":{"daily_original_length":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1526073"],"daily_original_length_application":"0","daily_original_length_unknown":"1526073","daily_original_length_via_data_reduction_proxy":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_original_length_via_data_reduction_proxy_application":"0","daily_original_length_via_data_reduction_proxy_unknown":"1515337","daily_original_length_via_data_reduction_proxy_video":"0","daily_original_length_video":"0","daily_original_length_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_original_length_with_data_reduction_proxy_enabled_application":"0","daily_original_length_with_data_reduction_proxy_enabled_unknown":"0","daily_original_length_with_data_reduction_proxy_enabled_video":"0","daily_received_length":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1526073"],"daily_received_length_application":"0","daily_received_length_https_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_long_bypass_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_short_bypass_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_unknown":"1526073","daily_received_length_unknown_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_via_data_reduction_proxy":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_via_data_reduction_proxy_application":"0","daily_received_length_via_data_reduction_proxy_unknown":"1515337","daily_received_length_via_data_reduction_proxy_video":"0","daily_received_length_video":"0","daily_received_length_with_data_reduction_proxy_enabled":["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"daily_received_length_with_data_reduction_proxy_enabled_application":"0","daily_received_length_with_data_reduction_proxy_enabled_unknown":"0","daily_received_length_with_data_reduction_proxy_enabled_video":"0","last_update_date":"13203723600000000","last_week_services_downstream_background_kb":{},"last_week_services_downstream_foreground_kb":{},"last_week_user_traffic_contenttype_downstream_kb":{},"network_properties":{},"this_week_number":2578,"this_week_services_downstream_background_kb":{},"this_week_services_downstream_foreground_kb":{"112189210":6,"35565745":0,"61656965":0,"65957842":1,"88863520":0,"95682324":3},"this_week_user_traffic_contenttype_downstream_kb":{"0":1480}},"extensions":{"alerts":{"initialized":true},"chrome_url_overrides":{},"last_chrome_version":"76.0.3803.0"},"gaia_cookie":{"changed_time":1559289377.368958,"hash":"2jmj7l5rSw0yVb/vlWAYkK/YBwk="},"gcm":{"product_category_for_subtypes":"org.chromium.windows","push_messaging_application_id_map":{"wp:https://propochki.ru/#177C9DEC-9D2A-499D-88C7-8BD3EE889-V2":"https://propochki.ru/#0"}},"google":{"services":{"signin_scoped_device_id":"9ad6b733-79aa-4773-bef2-f4ce1b0fb6d5"}},"http_original_content_length":"1526073","http_received_content_length":"1526073","invalidator":{"client_id":"csgUisLlRbNOskaQDoHg3w=="},"language_model_counters":{"ru":1},"media":{"device_id_salt":"83DA7DE6CA11893D0B5ACDA11319EBBE","engagement":{"schema_version":4}},"ntp":{"num_personal_suggestions":2},"plugins":{"plugins_list":[]},"previews":{"litepage":{"user-needs-notification":false},"offline_helper":{"available_pages":{}}},"profile":{"avatar_bubble_tutorial_shown":2,"avatar_index":26,"content_settings":{"exceptions":{"accessibility_events":{},"app_banner":{},"auto_select_certificate":{},"automatic_downloads":{},"autoplay":{},"background_sync":{},"bluetooth_guard":{},"bluetooth_scanning":{},"client_hints":{},"clipboard":{},"cookies":{},"durable_storage":{},"flash_data":{},"geolocation":{},"hid_chooser_data":{},"hid_guard":{},"images":{},"important_site_info":{},"intent_picker_auto_display":{},"javascript":{},"media_engagement":{"https://propochki.ru:443,*":{"last_modified":"13203763031691958","setting":{"audiblePlaybacks":0,"audioContextPlaybacks":0,"hasHighScore":false,"highScoreChanges":0,"lastMediaPlaybackTime":0.0,"mediaElementPlaybacks":0,"mediaPlaybacks":0,"significantPlaybacks":0,"visits":1,"visitsWithMediaTag":0}}},"media_stream_camera":{},"media_stream_mic":{},"midi_sysex":{},"mixed_script":{},"notifications":{"https://propochki.ru:443,*":{"last_modified":"13199014231047236","setting":1}},"password_protection":{},"payment_handler":{},"permission_autoblocking_data":{},"plugins":{},"popups":{},"ppapi_broker":{},"protocol_handler":{},"sensors":{},"serial_chooser_data":{},"serial_guard":{},"site_engagement":{"https://propochki.ru:443,*":{"last_modified":"13203762977511958","setting":{"lastEngagementTime":13203762977511958.0,"lastShortcutLaunchTime":0.0,"pointsAddedToday":3.0,"rawScore":3.0}}},"sound":{},"ssl_cert_decisions":{},"subresource_filter":{},"subresource_filter_data":{},"usb_chooser_data":{},"usb_guard":{}},"pref_version":1},"created_by_version":"75.0.3738.0","exit_type":"Normal","exited_cleanly":true,"last_engagement_time":"13203762977511958","managed_user_id":"","name":"Пользователь 1"},"signin":{"allowed":true},"translate_site_blacklist_with_time":{}}
    

    Вот этот код успешно выдергивает нужные мне строчки :

    VAR_PUSH_UNSUBSCRIBE_SITE_LAST_MODIFIED = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications["https://propochki.ru:443,*"].last_modified
    
    VAR_PUSH_UNSUBSCRIBE_SITE_SETTING = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications["https://propochki.ru:443,*"].setting
    

    Но как только заменяю на переменную,действие завершается с ошибкой :

    VAR_PUSH_UNSUBSCRIBE_SITE_LAST_MODIFIED = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications["[[PUSH_DOMAIN]]:443,*"].last_modified
    
    VAR_PUSH_UNSUBSCRIBE_SITE_SETTING = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications["[[PUSH_DOMAIN]]:443,*"].setting
    

    Если я правильно понимаю,то BAS не читает переменную и завершается с ошибкой.Подскажите,как в моем случае указать его в кавычках?



  • Насколько я помню, нужно удалить ковычки



  • [[PUSH_UNSUBSCRIBE_SITE_LAST_MODIFIED]] = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications[ [[PUSH_DOMAIN]] + ":443,*" ].last_modified
    
    [[PUSH_UNSUBSCRIBE_SITE_SETTING]] = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications[ [[PUSH_DOMAIN]] + ":443,*" ].setting
    


  • @ghostz said in Использование переменной в кавычках при парсинге JSON:

    [[PUSH_UNSUBSCRIBE_SITE_LAST_MODIFIED]] = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications[ [[PUSH_DOMAIN]] + ":443,*" ].last_modified

    [[PUSH_UNSUBSCRIBE_SITE_SETTING]] = JSON.parse([[PREFERENCES]]).profile.content_settings.exceptions.notifications[ [[PUSH_DOMAIN]] + ":443,*" ].setting

    Большое спасибо!)



  • @ls5stream без кавычек нельзя к сожалению(



  • @sir-ydroidrrr .notifications['"' + [[PUSH_DOMAIN]] + ':443,*"' ]


Log in to reply