How to parse JSON with VBA without external libraries?

前端 未结 3 603
囚心锁ツ
囚心锁ツ 2020-11-30 04:15

I have a json like below:

{\"sentences\":[{\"trans\":\"something ru\",\"orig\":\"english word\",\"translit\":\"Angliyskoye slovo\",\"src_translit\":\"\"}], \         


        
3条回答
  •  余生分开走
    2020-11-30 04:54

    I've found this script example useful (from http://www.mrexcel.com/forum/excel-questions/898899-json-api-excel.html#post4332075 ):

    Sub getData()
    
        Dim Movie As Object
        Dim scriptControl As Object
    
        Set scriptControl = CreateObject("MSScriptControl.ScriptControl")
        scriptControl.Language = "JScript"
    
        With CreateObject("MSXML2.XMLHTTP")
            .Open "GET", "http://www.omdbapi.com/?t=frozen&y=&plot=short&r=json", False
            .send
            Set Movie = scriptControl.Eval("(" + .responsetext + ")")
            .abort
            With Sheets(2)
                .Cells(1, 1).Value = Movie.Title
                .Cells(1, 2).Value = Movie.Year
                .Cells(1, 3).Value = Movie.Rated
                .Cells(1, 4).Value = Movie.Released
                .Cells(1, 5).Value = Movie.Runtime
                .Cells(1, 6).Value = Movie.Director
                .Cells(1, 7).Value = Movie.Writer
                .Cells(1, 8).Value = Movie.Actors
                .Cells(1, 9).Value = Movie.Plot
                .Cells(1, 10).Value = Movie.Language
                .Cells(1, 11).Value = Movie.Country
                .Cells(1, 12).Value = Movie.imdbRating
            End With
        End With
    
    End Sub
    

提交回复
热议问题