dotMobimobiThinkingmobiForgemobiReadyDeviceAtlasgoMobi

Posted by nbaum5 1 year 16 weeks ago

pic
 nbaum5
mobiForge Newbie
Posts: 6
Joined: 1 year ago
[offline]

I'm getting an error "Unable to load Json data" when trying to load the json file with getTreeFromFile. The data is not parsing into a hash. Should I be using a parser other rather than JSON.parse? Could the data file be corrupt somehow?

Thanks for any help!

Posted by daniel.hunt 1 year ago

pic
 daniel.hunt
dotMobi logo
Mobile Grandmaster
Posts: 230
Joined: 4 years ago
[offline]

Have you verified the file permissions of the JSON file itself? Does your script have the right to read from it?

Daniel Hunt
dotMobi

Posted by nbaum5 1 year ago

pic
 nbaum5
mobiForge Newbie
Posts: 6
Joined: 1 year ago
[offline]

Yes. I'm on Windows. I can read from the file and load its content just fine.

From the ruby command line, I do the following:

file = File.open(filename, 'r')
json = f.readlines.to_s
hash = JSON.parse(json)

Here is where it fails:

hash.kind_of?(Hash)
=> false

Posted by nbaum5 1 year ago

pic
 nbaum5
mobiForge Newbie
Posts: 6
Joined: 1 year ago
[offline]

obviously "json = f.readlines.to_s" should read: "json = file.readlines.to_s"

Posted by nbaum5 1 year ago

pic
 nbaum5
mobiForge Newbie
Posts: 6
Joined: 1 year ago
[offline]

Needed to use yajl-ruby instead of JSON.