@agronov

Почему не могу применть JSON.parse(data)?

Получил из PHP данные. Занес в переменную let data = '[{"nickname":"qwerty11","first_name":"\u0410\u043b\u0435\u043a\u0441\u0435\u0439","last_name":"","description":"\u041e\u041f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0440\u0430\u0442\u043a\u043e","rich_editing":"true","syntax_highlighting":"true","comment_shortcuts":"false","admin_color":"fresh","use_ssl":"0","show_admin_bar_front":"true","locale":"","wp_capabilities":"a:2:{s:10:\"subscriber\";b:1;s:6:\"partne\";b:1;}","wp_user_level":"0","ur_user_status":"1","dismissed_wp_pointers":"","user_registration_comp_name":"\u041e\u0440\u0430\u043b","ur_form_id":"382","user_registration_comp_address":"\u0420\u043e\u0441\u0441\u0438\u044f","user_registration_select_1571960755":"\u041f\u0435\u043d\u0437\u0430","user_registration_town":"\u041f\u0435\u043d\u0437\u0430","user_registration_input_box_1571866994":"+11111111111111","user_registration_profile_pic_id":"0"},{"nickname":"qwerty22","first_name":"\u0410\u043d\u044f","last_name":"","description":"12312qwadsda das dasdsdasdas asds as a","rich_editing":"true","syntax_highlighting":"true","comment_shortcuts":"false","admin_color":"fresh","use_ssl":"0","show_admin_bar_front":"true","locale":"","wp_capabilities":"a:1:{s:6:\"partne\";b:1;}","wp_user_level":"0","ur_user_status":"1","dismissed_wp_pointers":"","user_registration_comp_name":"\u041f\u043e\u043b\u043e","ur_form_id":"382","user_registration_comp_address":"\u041c\u043e\u0441\u043a\u0432\u0430,","user_registration_select_1571960755":"\u041c\u043e\u0441\u043a\u0432\u0430","user_registration_town":"\u041c\u043e\u0441\u043a\u0432\u0430","user_registration_input_box_1571866994":"+2222222222"}]'

Применяю JSON.parse(data) выдает ошибку "Uncaught SyntaxError: Unexpected token s in JSON at position 281 at JSON.parse ()"

Здесь все нормально переводит
  • Вопрос задан
  • 241 просмотр
Решения вопроса 2
Если говорит, что неправильный, значит неправильный
https://jsonlint.com/
Ответ написан
@Wyruweso
Вот так будет работать. Слэши надо тоже экранировать

JSON.parse('[{"nickname":"qwerty11","first_name":"\u0410\u043b\u0435\u043a\u0441\u0435\u0439","last_name":"","description":"\u041e\u041f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0440\u0430\u0442\u043a\u043e","rich_editing":"true","syntax_highlighting":"true","comment_shortcuts":"false","admin_color":"fresh","use_ssl":"0","show_admin_bar_front":"true","locale":"","wp_capabilities":"a:2:{s:10:\\"subscriber\\";b:1;s:6:\\"partne\\";b:1;}","wp_user_level":"0","ur_user_status":"1","dismissed_wp_pointers":"","user_registration_comp_name":"\u041e\u0440\u0430\u043b","ur_form_id":"382","user_registration_comp_address":"\u0420\u043e\u0441\u0441\u0438\u044f","user_registration_select_1571960755":"\u041f\u0435\u043d\u0437\u0430","user_registration_town":"\u041f\u0435\u043d\u0437\u0430","user_registration_input_box_1571866994":"+11111111111111","user_registration_profile_pic_id":"0"},{"nickname":"qwerty22","first_name":"\u0410\u043d\u044f","last_name":"","description":"12312qwadsda das dasdsdasdas asds as a","rich_editing":"true","syntax_highlighting":"true","comment_shortcuts":"false","admin_color":"fresh","use_ssl":"0","show_admin_bar_front":"true","locale":"","wp_capabilities":"a:1:{s:6:\\"partne\\";b:1;}","wp_user_level":"0","ur_user_status":"1","dismissed_wp_pointers":"","user_registration_comp_name":"\u041f\u043e\u043b\u043e","ur_form_id":"382","user_registration_comp_address":"\u041c\u043e\u0441\u043a\u0432\u0430,","user_registration_select_1571960755":"\u041c\u043e\u0441\u043a\u0432\u0430","user_registration_town":"\u041c\u043e\u0441\u043a\u0432\u0430","user_registration_input_box_1571866994":"+2222222222"}]')
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
24 нояб. 2024, в 14:37
3000 руб./в час
24 нояб. 2024, в 13:04
500 руб./в час
24 нояб. 2024, в 12:29
3000 руб./за проект