display values of couchdb document
I have a document stored in couchdb which is like开发者_StackOverflow this -
{
"_id": "0f8baf09c680abdc434607dc77000bad",
"_rev": "2-c989a4c672d25b678aadfa4c37212404",
"XI": "gl11subjects",
"XII": "gl12subjects"
}
when I retrieve the document using the code
@value = CouchRest.get("url/db/docid")
@value.each do |key, value|
puts "Key: "+key+"value: "+value+
The above statement prints all the values in the json file, including _id and _rev. How should I iterate through the @value to only get the key/value for XI and XII.
Here's one way:
@value.each do |key, value|
puts "Key: #{key} Value: #{value}" if key.include?("XI")
end
Inversely, you could do the following:
@value.each do |key, value|
puts "Key: #{key} Value: #{value}" unless key.include?("_")
end
精彩评论