Results 1 to 16 of 16

Thread: [RESOLVED] Read JSON file and Add ComboBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Resolved [RESOLVED] Read JSON file and Add ComboBox

    I am a novice, I try to create a software that allows me to automatically download videos from a database, I managed to extract the information from the database and create a URL, which downloads a JSON file, within the JSON there are URL's of the videos in different resolutions.

    I am trying to read the JSON file now. I would like it to read all the JSON files that I have in a folder, one by one, and if the user before all this process has selected the 720p resolution for the videos, just read the "progressiveDownloadURL": "https:// download -a.akamaihd.net/files/media_publication/bc/sjjm_S_138_r720P.mp4" from "label": "720p". And then download the video. This is what I have so far:

    Code:
    'Leer archivo JSON
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        End Sub
    
        Public Class File
            Public Property progressiveDownloadURL As String
            Public Property checksum As String
            Public Property filesize As Integer
            Public Property modifiedDatetime As DateTime
            Public Property bitRate As Double
            Public Property duration As Double
            Public Property frameHeight As Integer
            Public Property frameWidth As Integer
            Public Property label As String
            Public Property frameRate As Double
            Public Property mimetype As String
            Public Property subtitled As Boolean
        End Class
    
        Public Class Lss
            Public Property lg As String
        End Class
    
        Public Class Lsr
            Public Property xl As String
        End Class
    
        Public Class Pnr
            Public Property lg As String
        End Class
    
        Public Class Wss
            Public Property lg As String
            Public Property sm As String
        End Class
    
        Public Class Sqr
            Public Property lg As String
        End Class
    
        Public Class Images
            Public Property lss As Lss
            Public Property lsr As Lsr
            Public Property pnr As Pnr
            Public Property wss As Wss
            Public Property sqr As Sqr
        End Class
    
        Public Class Medium
            Public Property guid As String
            Public Property languageAgnosticNaturalKey As String
            Public Property naturalKey As String
            Public Property type As String
            Public Property primaryCategory As String
            Public Property title As String
            Public Property description As String
            Public Property firstPublished As DateTime
            Public Property duration As Double
            Public Property durationFormattedHHMM As String
            Public Property durationFormattedMinSec As String
            Public Property tags As String()
            Public Property files As File()
            Public Property images As Images
            Public Property availableLanguages As String()
            Public Property printReferences As String()
        End Class
    
        Public Class ReadJson
            Public Property media As Medium()
        End Class
    Do you know how I can read the progressiveDownloadURL along with the respective label? You can see the original JSON here. Here is the JSON of the first video:

    Code:
    {
      "media": [
        {
          "guid": "58fced68a25a39c2e32b2a31",
          "languageAgnosticNaturalKey": "pub-sjjm_138_VIDEO",
          "naturalKey": "pub-sjjm_S_138_VIDEO",
          "type": "video",
          "primaryCategory": "VODSJJMeetings",
          "title": "138. Los cabellos blancos, una hermosa corona",
          "description": "",
          "firstPublished": "2017-04-23T18:07:36.156Z",
          "duration": 174.847,
          "durationFormattedHHMM": "2:54",
          "durationFormattedMinSec": "2m 54s",
          "tags": [
            "AllVideosExclude"
          ],
          "files": [
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/04/sjjm_S_138_r240P.mp4",
              "checksum": "91fcbf300960cb78cf1046424f3f5be5",
              "filesize": 3331154,
              "modifiedDatetime": "2020-11-28T18:49:16.000Z",
              "bitRate": 148.84236289441625,
              "duration": 174.847,
              "frameHeight": 180,
              "frameWidth": 320,
              "label": "240p",
              "frameRate": 29.97,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/21/sjjm_S_138_r360P.mp4",
              "checksum": "618308967cc2d1954d71e7e285b56362",
              "filesize": 12360174,
              "modifiedDatetime": "2019-01-29T14:02:56.000Z",
              "bitRate": 552.3996486906765,
              "duration": 174.80796666667,
              "frameHeight": 360,
              "frameWidth": 640,
              "label": "360p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/c6/sjjm_S_138_r480P.mp4",
              "checksum": "07b7d3fb77f35c98c8b9dbcff253460e",
              "filesize": 16423369,
              "modifiedDatetime": "2019-01-29T14:02:59.000Z",
              "bitRate": 733.9915494650274,
              "duration": 174.80796666667,
              "frameHeight": 480,
              "frameWidth": 854,
              "label": "480p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/bc/sjjm_S_138_r720P.mp4",
              "checksum": "ce23f444c7bedd8b532afa42cdd883e1",
              "filesize": 35305633,
              "modifiedDatetime": "2019-01-29T14:03:03.000Z",
              "bitRate": 1577.8757860530081,
              "duration": 174.80796666667,
              "frameHeight": 720,
              "frameWidth": 1280,
              "label": "720p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            }
          ],
          "images": {
            "lss": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_lss_138_lg.jpg"
            },
            "lsr": {
              "xl": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_lsr_138_xl.jpg"
            },
            "pnr": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_pnr_138_lg.jpg"
            },
            "wss": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_wss_138_lg.jpg",
              "sm": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_wss_138_sm.jpg"
            },
            "sqr": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_sqr_138_lg.jpg"
            }
          },
          "availableLanguages": [
            "A",
            "ABB",
            "ABK",
            "AC",
            "AF",
            "AH",
            "AJ",
            "AJR",
            "AK",
            "AKA",
            "AKN",
            "AL",
            "ALT",
            "ALU",
            "AM",
            "AN",
            "AO",
            "AP",
            "AW",
            "AZ",
            "B",
            "BAK",
            "BI",
            "BL",
            "BM",
            "BO",
            "BQ",
            "BS",
            "BT",
            "BTK",
            "BU",
            "BZK",
            "C",
            "CA",
            "CB",
            "CE",
            "CG",
            "CGM",
            "CH",
            "CHC",
            "CHH",
            "CHL",
            "CHS",
            "CIN",
            "CK",
            "CN",
            "CNS",
            "CO",
            "CPI",
            "CR",
            "CT",
            "CU",
            "CV",
            "CW",
            "D",
            "DA",
            "DG",
            "DK",
            "DM",
            "DMR",
            "DR",
            "DU",
            "E",
            "ED",
            "EF",
            "EG",
            "EW",
            "F",
            "FD",
            "FI",
            "FN",
            "FO",
            "FR",
            "FT",
            "G",
            "GA",
            "GB",
            "GE",
            "GHM",
            "GI",
            "GLC",
            "GN",
            "GRF",
            "GUR",
            "H",
            "HA",
            "HI",
            "HK",
            "HR",
            "HSK",
            "HV",
            "I",
            "IA",
            "IB",
            "IBI",
            "IC",
            "IG",
            "IH",
            "IK",
            "IL",
            "IN",
            "IS",
            "J",
            "JA",
            "JCR",
            "K",
            "KAB",
            "KB",
            "KBR",
            "KBV",
            "KD",
            "KG",
            "KI",
            "KIM",
            "KIN",
            "KO",
            "KQ",
            "KR",
            "KRI",
            "KSN",
            "KU",
            "KY",
            "KZ",
            "L",
            "LA",
            "LAH",
            "LD",
            "LE",
            "LF",
            "LHK",
            "LI",
            "LJ",
            "LM",
            "LO",
            "LS",
            "LT",
            "LU",
            "LUC",
            "LV",
            "LVA",
            "LWX",
            "M",
            "MAC",
            "MAY",
            "MAZ",
            "MBD",
            "MC",
            "MG",
            "MGL",
            "MH",
            "MK",
            "ML",
            "MM",
            "MO",
            "MP",
            "MPD",
            "MT",
            "MWL",
            "MX",
            "MXG",
            "MY",
            "MZ",
            "N",
            "NBL",
            "NBZ",
            "NDA",
            "NEN",
            "NGB",
            "NGL",
            "NGP",
            "NHC",
            "NHG",
            "NHH",
            "NHT",
            "NI",
            "NK",
            "NM",
            "NMB",
            "NN",
            "NP",
            "NSM",
            "NV",
            "NYU",
            "NZ",
            "O",
            "OA",
            "OG",
            "OKP",
            "OS",
            "OSS",
            "OT",
            "OTM",
            "P",
            "PA",
            "PCM",
            "PGW",
            "PHN",
            "PJ",
            "PMR",
            "PN",
            "PP",
            "PR",
            "PU",
            "Q",
            "QC",
            "QIC",
            "QII",
            "QIP",
            "QIT",
            "QU",
            "QUA",
            "QUB",
            "QUL",
            "QUN",
            "RA",
            "RD",
            "RDC",
            "RDU",
            "REA",
            "RM",
            "RMC",
            "RME",
            "RMG",
            "RMS",
            "RMX",
            "RN",
            "RR",
            "RT",
            "RU",
            "S",
            "SA",
            "SB",
            "SBO",
            "SC",
            "SD",
            "SE",
            "SEN",
            "SG",
            "SGR",
            "SH",
            "SHU",
            "SI",
            "SK",
            "SM",
            "SN",
            "SP",
            "SPL",
            "SR",
            "SRM",
            "SSA",
            "ST",
            "SU",
            "SV",
            "SW",
            "SWI",
            "T",
            "TAT",
            "TB",
            "TCN",
            "TE",
            "TEW",
            "TG",
            "TH",
            "TI",
            "TJO",
            "TK",
            "TL",
            "TLN",
            "TMR",
            "TN",
            "TO",
            "TOT",
            "TPO",
            "TRS",
            "TS",
            "TTP",
            "TU",
            "TV",
            "TW",
            "TZE",
            "TZO",
            "U",
            "UB",
            "UD",
            "UM",
            "UR",
            "UZ",
            "V",
            "VE",
            "VL",
            "VLC",
            "VT",
            "W",
            "WA",
            "WG",
            "WL",
            "WY",
            "X",
            "XO",
            "YA",
            "YCB",
            "YP",
            "YR",
            "YW",
            "Z",
            "ZN",
            "ZPI",
            "ZS",
            "ZU"
          ],
          "printReferences": [
            "sjjm-138.v",
            "sjjm-138"
          ]
        }
      ]
    }
    I want that if in a ComboBox, I select 720p, it downloads the video from the progressiveDownloadURL that says "label": "720p", that it downloads all the JSON files one by one. if I make myself understood? I would really appreciate your code input.
    Last edited by livrasand; Aug 17th, 2022 at 12:29 PM. Reason: New problem in coding

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    I am a novice, I try to create a software that allows me to automatically download videos from a database, I managed to extract the information from the database and create a URL, which downloads a JSON file, within the JSON there are URL's of the videos in different resolutions.

    I am trying to read the JSON file now. I would like it to read all the JSON files that I have in a folder, one by one, and if the user before all this process has selected the 720p resolution for the videos, just read the "progressiveDownloadURL": "https:// download -a.akamaihd.net/files/media_publication/bc/sjjm_S_138_r720P.mp4" from "label": "720p". And then download the video. This is what I have so far:

    Code:
    'Leer archivo JSON
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
        End Sub
    
        Public Class File
            Public Property progressiveDownloadURL As String
            Public Property checksum As String
            Public Property filesize As Integer
            Public Property modifiedDatetime As DateTime
            Public Property bitRate As Double
            Public Property duration As Double
            Public Property frameHeight As Integer
            Public Property frameWidth As Integer
            Public Property label As String
            Public Property frameRate As Double
            Public Property mimetype As String
            Public Property subtitled As Boolean
        End Class
    
        Public Class Lss
            Public Property lg As String
        End Class
    
        Public Class Lsr
            Public Property xl As String
        End Class
    
        Public Class Pnr
            Public Property lg As String
        End Class
    
        Public Class Wss
            Public Property lg As String
            Public Property sm As String
        End Class
    
        Public Class Sqr
            Public Property lg As String
        End Class
    
        Public Class Images
            Public Property lss As Lss
            Public Property lsr As Lsr
            Public Property pnr As Pnr
            Public Property wss As Wss
            Public Property sqr As Sqr
        End Class
    
        Public Class Medium
            Public Property guid As String
            Public Property languageAgnosticNaturalKey As String
            Public Property naturalKey As String
            Public Property type As String
            Public Property primaryCategory As String
            Public Property title As String
            Public Property description As String
            Public Property firstPublished As DateTime
            Public Property duration As Double
            Public Property durationFormattedHHMM As String
            Public Property durationFormattedMinSec As String
            Public Property tags As String()
            Public Property files As File()
            Public Property images As Images
            Public Property availableLanguages As String()
            Public Property printReferences As String()
        End Class
    
        Public Class ReadJson
            Public Property media As Medium()
        End Class
    Do you know how I can read the progressiveDownloadURL along with the respective label? You can see the original JSON here. Here is the JSON of the first video:

    Code:
    {
      "media": [
        {
          "guid": "58fced68a25a39c2e32b2a31",
          "languageAgnosticNaturalKey": "pub-sjjm_138_VIDEO",
          "naturalKey": "pub-sjjm_S_138_VIDEO",
          "type": "video",
          "primaryCategory": "VODSJJMeetings",
          "title": "138. Los cabellos blancos, una hermosa corona",
          "description": "",
          "firstPublished": "2017-04-23T18:07:36.156Z",
          "duration": 174.847,
          "durationFormattedHHMM": "2:54",
          "durationFormattedMinSec": "2m 54s",
          "tags": [
            "AllVideosExclude"
          ],
          "files": [
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/04/sjjm_S_138_r240P.mp4",
              "checksum": "91fcbf300960cb78cf1046424f3f5be5",
              "filesize": 3331154,
              "modifiedDatetime": "2020-11-28T18:49:16.000Z",
              "bitRate": 148.84236289441625,
              "duration": 174.847,
              "frameHeight": 180,
              "frameWidth": 320,
              "label": "240p",
              "frameRate": 29.97,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/21/sjjm_S_138_r360P.mp4",
              "checksum": "618308967cc2d1954d71e7e285b56362",
              "filesize": 12360174,
              "modifiedDatetime": "2019-01-29T14:02:56.000Z",
              "bitRate": 552.3996486906765,
              "duration": 174.80796666667,
              "frameHeight": 360,
              "frameWidth": 640,
              "label": "360p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/c6/sjjm_S_138_r480P.mp4",
              "checksum": "07b7d3fb77f35c98c8b9dbcff253460e",
              "filesize": 16423369,
              "modifiedDatetime": "2019-01-29T14:02:59.000Z",
              "bitRate": 733.9915494650274,
              "duration": 174.80796666667,
              "frameHeight": 480,
              "frameWidth": 854,
              "label": "480p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            },
            {
              "progressiveDownloadURL": "https://download-a.akamaihd.net/files/media_publication/bc/sjjm_S_138_r720P.mp4",
              "checksum": "ce23f444c7bedd8b532afa42cdd883e1",
              "filesize": 35305633,
              "modifiedDatetime": "2019-01-29T14:03:03.000Z",
              "bitRate": 1577.8757860530081,
              "duration": 174.80796666667,
              "frameHeight": 720,
              "frameWidth": 1280,
              "label": "720p",
              "frameRate": 44.056,
              "mimetype": "video/mp4",
              "subtitled": false
            }
          ],
          "images": {
            "lss": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_lss_138_lg.jpg"
            },
            "lsr": {
              "xl": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_lsr_138_xl.jpg"
            },
            "pnr": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_pnr_138_lg.jpg"
            },
            "wss": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_wss_138_lg.jpg",
              "sm": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_wss_138_sm.jpg"
            },
            "sqr": {
              "lg": "https://assetsnffrgf-a.akamaihd.net/assets/m/sjjm/univ/art/sjjm_univ_sqr_138_lg.jpg"
            }
          },
          "availableLanguages": [
            "A",
            "ABB",
            "ABK",
            "AC",
            "AF",
            "AH",
            "AJ",
            "AJR",
            "AK",
            "AKA",
            "AKN",
            "AL",
            "ALT",
            "ALU",
            "AM",
            "AN",
            "AO",
            "AP",
            "AW",
            "AZ",
            "B",
            "BAK",
            "BI",
            "BL",
            "BM",
            "BO",
            "BQ",
            "BS",
            "BT",
            "BTK",
            "BU",
            "BZK",
            "C",
            "CA",
            "CB",
            "CE",
            "CG",
            "CGM",
            "CH",
            "CHC",
            "CHH",
            "CHL",
            "CHS",
            "CIN",
            "CK",
            "CN",
            "CNS",
            "CO",
            "CPI",
            "CR",
            "CT",
            "CU",
            "CV",
            "CW",
            "D",
            "DA",
            "DG",
            "DK",
            "DM",
            "DMR",
            "DR",
            "DU",
            "E",
            "ED",
            "EF",
            "EG",
            "EW",
            "F",
            "FD",
            "FI",
            "FN",
            "FO",
            "FR",
            "FT",
            "G",
            "GA",
            "GB",
            "GE",
            "GHM",
            "GI",
            "GLC",
            "GN",
            "GRF",
            "GUR",
            "H",
            "HA",
            "HI",
            "HK",
            "HR",
            "HSK",
            "HV",
            "I",
            "IA",
            "IB",
            "IBI",
            "IC",
            "IG",
            "IH",
            "IK",
            "IL",
            "IN",
            "IS",
            "J",
            "JA",
            "JCR",
            "K",
            "KAB",
            "KB",
            "KBR",
            "KBV",
            "KD",
            "KG",
            "KI",
            "KIM",
            "KIN",
            "KO",
            "KQ",
            "KR",
            "KRI",
            "KSN",
            "KU",
            "KY",
            "KZ",
            "L",
            "LA",
            "LAH",
            "LD",
            "LE",
            "LF",
            "LHK",
            "LI",
            "LJ",
            "LM",
            "LO",
            "LS",
            "LT",
            "LU",
            "LUC",
            "LV",
            "LVA",
            "LWX",
            "M",
            "MAC",
            "MAY",
            "MAZ",
            "MBD",
            "MC",
            "MG",
            "MGL",
            "MH",
            "MK",
            "ML",
            "MM",
            "MO",
            "MP",
            "MPD",
            "MT",
            "MWL",
            "MX",
            "MXG",
            "MY",
            "MZ",
            "N",
            "NBL",
            "NBZ",
            "NDA",
            "NEN",
            "NGB",
            "NGL",
            "NGP",
            "NHC",
            "NHG",
            "NHH",
            "NHT",
            "NI",
            "NK",
            "NM",
            "NMB",
            "NN",
            "NP",
            "NSM",
            "NV",
            "NYU",
            "NZ",
            "O",
            "OA",
            "OG",
            "OKP",
            "OS",
            "OSS",
            "OT",
            "OTM",
            "P",
            "PA",
            "PCM",
            "PGW",
            "PHN",
            "PJ",
            "PMR",
            "PN",
            "PP",
            "PR",
            "PU",
            "Q",
            "QC",
            "QIC",
            "QII",
            "QIP",
            "QIT",
            "QU",
            "QUA",
            "QUB",
            "QUL",
            "QUN",
            "RA",
            "RD",
            "RDC",
            "RDU",
            "REA",
            "RM",
            "RMC",
            "RME",
            "RMG",
            "RMS",
            "RMX",
            "RN",
            "RR",
            "RT",
            "RU",
            "S",
            "SA",
            "SB",
            "SBO",
            "SC",
            "SD",
            "SE",
            "SEN",
            "SG",
            "SGR",
            "SH",
            "SHU",
            "SI",
            "SK",
            "SM",
            "SN",
            "SP",
            "SPL",
            "SR",
            "SRM",
            "SSA",
            "ST",
            "SU",
            "SV",
            "SW",
            "SWI",
            "T",
            "TAT",
            "TB",
            "TCN",
            "TE",
            "TEW",
            "TG",
            "TH",
            "TI",
            "TJO",
            "TK",
            "TL",
            "TLN",
            "TMR",
            "TN",
            "TO",
            "TOT",
            "TPO",
            "TRS",
            "TS",
            "TTP",
            "TU",
            "TV",
            "TW",
            "TZE",
            "TZO",
            "U",
            "UB",
            "UD",
            "UM",
            "UR",
            "UZ",
            "V",
            "VE",
            "VL",
            "VLC",
            "VT",
            "W",
            "WA",
            "WG",
            "WL",
            "WY",
            "X",
            "XO",
            "YA",
            "YCB",
            "YP",
            "YR",
            "YW",
            "Z",
            "ZN",
            "ZPI",
            "ZS",
            "ZU"
          ],
          "printReferences": [
            "sjjm-138.v",
            "sjjm-138"
          ]
        }
      ]
    }
    I want that if in a ComboBox, I select 720p, it downloads the video from the progressiveDownloadURL that says "label": "720p", that it downloads all the JSON files one by one. if I make myself understood? I would really appreciate your code input.
    Assuming you have added a reference to Newtonsoft.Json then the following code should read all .json files in the same folder as the executable (probably a bad idea, put the files somewhere better) and then query them for the 720p label, returning a list of the urls.

    Code:
     Dim files As New List(Of Medium)
            Dim jsonFiles = Directory.GetFiles(".", "*.json")
    
            For Each jsonFile In jsonFiles
                Using reader = New StreamReader(jsonFile)
                    Dim json = Await reader.ReadToEndAsync()
                    Dim file = JsonConvert.DeserializeObject(Of ReadJson)(json)
                    If file.media IsNot Nothing Then
                        files.AddRange(file.media)
                    End If
                End Using
            Next
    
            Dim res = files.SelectMany(Function(m) m.files).Where(Function(m) m.label = "720p").Select(Function(x) x.progressiveDownloadURL).ToList()

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    Many thanks!! I had 18 days without being able to solve it, thanks friend, how could I make it download the videos at once?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    I'm trying to see the list items with this, but it gives me the next error: The argument "Prompt" cannot be converted to type "String".

    Code:
    'Leer archivo JSON
        Private Async Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Try
                Dim files As New List(Of Medium)
                Dim jsonFiles = Directory.GetFiles("C:\GoAttendant\Attendant Zoom\AppData\Local\Packages\417474656E64616E74205A6F6F6D\", "*.json")
    
                For Each jsonFile In jsonFiles
                    Using reader = New StreamReader(jsonFile)
                        Dim json = Await reader.ReadToEndAsync()
                        Dim file = JsonConvert.DeserializeObject(Of ReadJson)(json)
                        If file.media IsNot Nothing Then
                            files.AddRange(file.media)
                        End If
                    End Using
                Next
                Dim res = files.SelectMany(Function(m) m.files).Where(Function(m) m.label = "720p").Select(Function(x) x.progressiveDownloadURL).ToList()
    
                For Each file In files
                    Try
                        MsgBox(file)
                    Catch ex As Exception
                        MsgBox("No ha sido posible visualizar los JSON porque: " & ex.Message)
                    End Try
                Next
            Catch ex As Exception
                MsgBox("No ha sido leer el JSON porque: " & ex.Message)
            End Try
        End Sub

  5. #5
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    I'm trying to see the list items with this, but it gives me the next error: The argument "Prompt" cannot be converted to type "String".

    Code:
    'Leer archivo JSON
        Private Async Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Try
                Dim files As New List(Of Medium)
                Dim jsonFiles = Directory.GetFiles("C:\GoAttendant\Attendant Zoom\AppData\Local\Packages\417474656E64616E74205A6F6F6D\", "*.json")
    
                For Each jsonFile In jsonFiles
                    Using reader = New StreamReader(jsonFile)
                        Dim json = Await reader.ReadToEndAsync()
                        Dim file = JsonConvert.DeserializeObject(Of ReadJson)(json)
                        If file.media IsNot Nothing Then
                            files.AddRange(file.media)
                        End If
                    End Using
                Next
                Dim res = files.SelectMany(Function(m) m.files).Where(Function(m) m.label = "720p").Select(Function(x) x.progressiveDownloadURL).ToList()
    
                For Each file In files
                    Try
                        MsgBox(file)
                    Catch ex As Exception
                        MsgBox("No ha sido posible visualizar los JSON porque: " & ex.Message)
                    End Try
                Next
            Catch ex As Exception
                MsgBox("No ha sido leer el JSON porque: " & ex.Message)
            End Try
        End Sub
    Which line is throwing that error?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    Code:
    For Each file In files
                    Try
                        MsgBox(file)
                    Catch ex As Exception
                        MsgBox("No ha sido posible visualizar los JSON porque: " & ex.Message)
                    End Try
                Next
    Attachment 185508

    Apparently this is when I want it to show me the progressiveDownloadURL

  7. #7
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    Code:
    For Each file In files
                    Try
                        MsgBox(file)
                    Catch ex As Exception
                        MsgBox("No ha sido posible visualizar los JSON porque: " & ex.Message)
                    End Try
                Next
    Attachment 185508

    Apparently this is when I want it to show me the progressiveDownloadURL
    The attachment isn't working, however files is a list of Medium objects, not sure what you are expecting MsgBox to display. Also as this is VB.Net you might be better off using MessageBox.Show rather than the legacy MsgBox function.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    What I expect the MsgBox to show is the progressiveDownloadURL (https://download-a.akamaihd.net/file..._138_r720P.mp4), to see that there are no errors, and then use DownloadFile to download all the videos from the files List. But I can't be successful.

    I have uploaded the image in the original resolution to my server, click here to see the error.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    Done, I've done it!!! It gives me all the URLs of all the JSON files in 720p, you're great man!!!

    I did it with this code snippet:
    Code:
    MessageBox.Show(String.Join(",", res))
    Now, I will try to download the videos

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    I already solved it, thank you very much for the support friend.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    Hi, now I have this JSON:

    languages.json

    And I have the next class:

    Code:
    Public Class Language
            Public Property symbol As String
            Public Property langcode As String
            Public Property name As String
            Public Property vernacularName As String
            Public Property script As String
            Public Property altSpellings As String()
            Public Property direction As String
            Public Property isSignLanguage As Boolean
            Public Property isCounted As Boolean
            Public Property hasWebContent As Boolean
        End Class
    
        Public Class Idiomas
            Public Property status As Integer
            Public Property languages As Language()
            Public Property localizedCount As String
        End Class
    I want to get just the vernacularName and add it to a ComboBox as an option, but I'm not successful.

  12. #12
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    Hi, now I have this JSON:

    languages.json

    And I have the next class:

    Code:
    Public Class Language
            Public Property symbol As String
            Public Property langcode As String
            Public Property name As String
            Public Property vernacularName As String
            Public Property script As String
            Public Property altSpellings As String()
            Public Property direction As String
            Public Property isSignLanguage As Boolean
            Public Property isCounted As Boolean
            Public Property hasWebContent As Boolean
        End Class
    
        Public Class Idiomas
            Public Property status As Integer
            Public Property languages As Language()
            Public Property localizedCount As String
        End Class
    I want to get just the vernacularName and add it to a ComboBox as an option, but I'm not successful.
    What have you tried so far? When you say you weren't successful what happened and how did it differ to what you expected to happen?

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    I tried the next code, but could not:

    Code:
    'Leer archivo JSON y descargar videos
            Try
                Dim files As New List(Of Idiomas)
                Dim jsonFiles = Directory.GetFiles("C:\GoAttendant\Attendant Zoom\AppData\Local\Packages\417474656E64616E74205A6F6F6D\", "*.json")
    
                'Lee el archivo JSON
                For Each jsonFile In jsonFiles
                    Using reader = New StreamReader(jsonFile)
                        Dim json = Await reader.ReadToEndAsync()
                        Dim file = JsonConvert.DeserializeObject(Of Idiomas)(json)
                        If file.languages IsNot Nothing Then
                            files.AddRange(file.languages)
                        End If
                    End Using
                Next
    
                    'Obtiene la URL del video según la resolución seleccionada
                    Dim res = files.SelectMany(Function(m) m.languages).Select(Function(x) x.vernacularName ).ToList()
    
                    'Agrega la URL del video a la lista de direcciones
                    Try
                        ComboBox1.Items.Add(res)
                    Catch ex As Exception
                        MsgBox("No se agregaron los URL's de los videos a la lista porque: " & ex.Message)
                    End Try

  14. #14
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    I tried the next code, but could not:

    Code:
    'Leer archivo JSON y descargar videos
            Try
                Dim files As New List(Of Idiomas)
                Dim jsonFiles = Directory.GetFiles("C:\GoAttendant\Attendant Zoom\AppData\Local\Packages\417474656E64616E74205A6F6F6D\", "*.json")
    
                'Lee el archivo JSON
                For Each jsonFile In jsonFiles
                    Using reader = New StreamReader(jsonFile)
                        Dim json = Await reader.ReadToEndAsync()
                        Dim file = JsonConvert.DeserializeObject(Of Idiomas)(json)
                        If file.languages IsNot Nothing Then
                            files.AddRange(file.languages)
                        End If
                    End Using
                Next
    
                    'Obtiene la URL del video según la resolución seleccionada
                    Dim res = files.SelectMany(Function(m) m.languages).Select(Function(x) x.vernacularName ).ToList()
    
                    'Agrega la URL del video a la lista de direcciones
                    Try
                        ComboBox1.Items.Add(res)
                    Catch ex As Exception
                        MsgBox("No se agregaron los URL's de los videos a la lista porque: " & ex.Message)
                    End Try
    Does your code throw any errors? If you step through it in a debugger is it correctly loading the json files and deserialising them?

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Aug 2022
    Posts
    31

    Re: Read multiple JSON files

    The error is in adding to ComboBox1, it does not add it.

  16. #16
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: Read multiple JSON files

    Quote Originally Posted by livrasand View Post
    The error is in adding to ComboBox1, it does not add it.
    Does it give an error?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width