简体   繁体   中英

Don't understand how to parse json

data = {
  "CEO": "William Hummel",
  "CFO": "Carla Work"
  }

I'm trying to parse the json data above with JSON.parse(data) in IRC, but it won't work.

I'm getting the following error: "SyntaxError: (irb):44: syntax error, unexpected ':', expecting tASSOC"

JSON.parse takes a string argument. You are trying to construct a Hash using JSON syntax. Use a string instead:

data = '{"CEO": "William Hummel", "CFO": "Carla Work"}'
JSON.parse(data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM