h-Klok / StatsWithJuliaBook

https://statisticswithjulia.org/
MIT License
1.08k stars 279 forks source link

Wrong jsonCode URL in listing 1.9 #21

Closed marcelovilla closed 3 years ago

marcelovilla commented 4 years ago

The URL for the jsonCode.json file in the draft is: https://raw.githubusercontent.com/h-Klok/StatsWithJuliaBook/master/1_chapter/jsonCode.json However, the correct URL is: https://raw.githubusercontent.com/h-Klok/StatsWithJuliaBook/master/data/jsonCode.json

ElvisCasco commented 4 years ago

Even replacing the URL it gets an error, I used the next code to run the code:

jsonWords = "{\"words\" : [\"heaven\",\"hell\",\"man\",\"woman\",\"boy\",\"girl\", \"king\",\"queen\",\"prince\",\"sir\",\"love\",\"hate\", \"knife\",\"english\",\"england\",\"god\"], \"numToShow\" : 5}"

marcelovilla commented 4 years ago

The URL works for me:

jsonUrl = "https://raw.githubusercontent.com/h-Klok/StatsWithJuliaBook/master/data/jsonCode.json"
jsonWords = HTTP.request("GET", jsonUrl)
parsedJsonDict = JSON.parse(String(jsonWords.body))
ElvisCasco commented 4 years ago

The code gets an error when it is used in Atom, that's why I created "jsonWords":

MethodError: no method matching parse(::HTTP.Messages.Response) Closest candidates are: parse(!Matched::AbstractString; dicttype, inttype, allownan, null) at C:\Users\USER.juliapro\JuliaPro_v1.4.2-1\packages\JSON\d89fA\src\Parser.jl:461 parse(!Matched::IO; dicttype, inttype, allownan, null) at C:\Users\USER.juliapro\JuliaPro_v1.4.2-1\packages\JSON\d89fA\src\Parser.jl:492 top-level scope at Statistics_with_Julia.jl:170

marcelovilla commented 4 years ago

Are you importing the modules with using HTTP, JSON on top of your file?

ElvisCasco commented 4 years ago

Yes, I was:

Listing 1.9: Web interface, JSON and string parsing

using HTTP, JSON

data = HTTP.request("GET", "https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt") shakespeare = String(data.body) shakespeareWords = split(shakespeare)

yoninazarathy commented 3 years ago

Thank you very much. Good catch. We fixed this.