I have DateAndJson.txt and want to analyse it.

data = Import["http://home.ustc.edu.cn/~xiaozh/SE/DateAndJson.txt", "List", CharacterEncoding -> "UTF-8"];
date = DateObject /@ data[[;; ;; 2]]
jsondata = data[[2 ;; ;; 2]];

Using this I got error.

ImportString[#, "JSON"] & /@ jsondata

I try to only handle one json object into Mathematica:

Import["http://home.ustc.edu.cn/~xiaozh/SE/SmallJson.txt", "JSON", CharacterEncoding -> "UTF-8"]
(*got the right json but characters display are wrong*)

So how to interpreter the DateAndJson.txt that make it can be analyse in Mathematica?

  • 2
    $\begingroup$ You need this ImportString[ Import[LocalAddress, CharacterEncoding -> "CP936"], "RawJSON"] or this ExportString[Import[LocalAddress,CharacterEncoding->"CP936"],"RawJSON"] $\endgroup$ – yode Dec 23 '16 at 15:16
  • 1
    $\begingroup$ @yode: I think the trick is to use "RawJSON" instead of "JSON". The ImportString then also works when Import uses CharacterEncoding -> "UTF-8". I think UTF-8 the prefered encoding for JSON and thus if in doubt makes more sense. I don't see an indication that the data is not UTF-8 encoded but I honestly don't know any of the chinese... $\endgroup$ – Albert Retey Dec 23 '16 at 21:05
  • $\begingroup$ @yode Thank you! It can works now! $\endgroup$ – partida Dec 24 '16 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.