Спарсить JSON строку

Поддержка
  • Всем привет. Не получается спарсить JSON строку.

    {"status":"ok","comments":[{"id":1514531032,"publisherId":"623cafa9f4d7ff38d0b8c971","documentId":"native:63e63d60a5d6444fdba1ceef","createdTs":1676136461891,"authorId":1746565850,"authorUid":1746565850,"authorPublisherId":"63cd0c458238741554887904","asPublisher":true,"text":"Спасибо автору","rootId":0,"replyToId":0,"visibility":"visible","editableUntilTs":1676140061891,"version":1,"images":[],"isPinned":false,"hasAuthorLike":false}],"authors":[{"uid":1746565850,"name":"Константин Савельев","displayName":"Константин Савельев","publicId":"0km64huzf90tvyvq086ry9t4hc","avatar":{"isEmpty":true,"avatarUrl":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig"},"userMainColor":"#DA9D8B","channelName":"Константин Савельев","channelLogo":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig","channelUrl":"/id/63cd0c458238741554887904"}],"users":[{"publicId":"0km64huzf90tvyvq086ry9t4hc","uid":1746565850,"name":"Константин Савельев","displayName":"Константин Савельев","avatar":{"isEmpty":true,"avatarUrl":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig"},"mainColor":"#DA9D8B"}],"publishers":[{"uid":1746565850,"publisherId":"63cd0c458238741554887904","name":"Константин Савельев","logo":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig","url":"/id/63cd0c458238741554887904","withCustomAvatar":false,"isVerified":false}],"profiles":[],"likersUids":[],"counters":[{"id":1514531032,"childrenCount":0,"likes":0,"dislikes":0,"index":0}],"serverTs":1676136461899,"publicationLikeCount":0,"emojis":[],"systemNotifications":[],"systemNotification":{"likesCount":0,"subscriptionsCount":0,"firstNotificationsWithNames":[]},"deletedCommentIds":[],"documentsPreviewInfos":[],"userReactions":{"likedComments":[],"dislikedComments":[],"userComplains":[],"authorLiked":[]},"subscribers":[]}
    

    Нужно спарсить значение id. Пробовал и через кубик и таким способом:

    var json = JSON.parse([[SAVED_CONTENT]])['id']
    
  • @suvorov_jr2 said in Спарсить JSON строку:

    Всем привет. Не получается спарсить JSON строку.

    {"status":"ok","comments":[{"id":1514531032,"publisherId":"623cafa9f4d7ff38d0b8c971","documentId":"native:63e63d60a5d6444fdba1ceef","createdTs":1676136461891,"authorId":1746565850,"authorUid":1746565850,"authorPublisherId":"63cd0c458238741554887904","asPublisher":true,"text":"Спасибо автору","rootId":0,"replyToId":0,"visibility":"visible","editableUntilTs":1676140061891,"version":1,"images":[],"isPinned":false,"hasAuthorLike":false}],"authors":[{"uid":1746565850,"name":"Константин Савельев","displayName":"Константин Савельев","publicId":"0km64huzf90tvyvq086ry9t4hc","avatar":{"isEmpty":true,"avatarUrl":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig"},"userMainColor":"#DA9D8B","channelName":"Константин Савельев","channelLogo":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig","channelUrl":"/id/63cd0c458238741554887904"}],"users":[{"publicId":"0km64huzf90tvyvq086ry9t4hc","uid":1746565850,"name":"Константин Савельев","displayName":"Константин Савельев","avatar":{"isEmpty":true,"avatarUrl":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig"},"mainColor":"#DA9D8B"}],"publishers":[{"uid":1746565850,"publisherId":"63cd0c458238741554887904","name":"Константин Савельев","logo":"https://avatars.dzeninfra.ru/get-zen_social/1535150/stubLogo3/orig","url":"/id/63cd0c458238741554887904","withCustomAvatar":false,"isVerified":false}],"profiles":[],"likersUids":[],"counters":[{"id":1514531032,"childrenCount":0,"likes":0,"dislikes":0,"index":0}],"serverTs":1676136461899,"publicationLikeCount":0,"emojis":[],"systemNotifications":[],"systemNotification":{"likesCount":0,"subscriptionsCount":0,"firstNotificationsWithNames":[]},"deletedCommentIds":[],"documentsPreviewInfos":[],"userReactions":{"likedComments":[],"dislikedComments":[],"userComplains":[],"authorLiked":[]},"subscribers":[]}
    

    Нужно спарсить значение id. Пробовал и через кубик и таким способом:

    var json = JSON.parse([[SAVED_CONTENT]])['id']
    

    Значение какого id? В "counters" или в "comments"?

  • @Fox
    comments

  • Идете сюда например https://jsonformatter.curiousconcept.com/#
    вставляете свой Json
    и наглядно видите структуру.
    далее
    Screen Shot 2023-02-11 at 22.58.30.png

    Screen Shot 2023-02-11 at 23.02.38.png

    Screen Shot 2023-02-11 at 23.02.57.png

    ну тоесть вашь path будет таким

    comments[0].id
    
  • @Bigma
    Спасибо)