作为对api调用的响应,我得到了这个json。我需要获得注释,以便在测试中验证它。我在响应中只会得到一条记录。如何访问注释值“意大利食谱”?我做了JSON.parse(响应)并得到了ruby散列。我需要帮助从散列中提取值。
{
“recipe”:{
"id":10,
"created_at":"2019-03-16T22:21:03Z",
"updated_at":"2019-03-16T23:07:07Z",
},
"audit":{
"id":402216837440,
"recipe_id":10,
"created_at":"2019-03-16T23:07:07Z",
"events":[
{
"id":402216837460,
"author_id":179,
"Comment":"Italian Recipes.",
"audit_id":402216837440
}
],
"via":{
"channel":"api"
}
}
}
我试过了,但我认为这不是正确的格式。我得到了错误。需要正确语法方面的帮助。
parsed_response = JSON.parse(res)
parsed_response['audit']['events']['comment']
发布于 2019-03-16 23:52:13
json_data = JSON.parse(json_string)
comment = json_data['audit']['events'].first['Comment']
recipe_id = json_data['recipe']['id']
https://stackoverflow.com/questions/55202603
复制