如何使用coffeescript迭代JSON散列 [英] How to iterate through JSON hash with coffeescript

查看:112
本文介绍了如何使用coffeescript迭代JSON散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Coffeescript,我在解决问题时遇到问题。我有一个JSON对象,当前存储在一个变量。如何迭代JSON对象中的键以显示键名称和与其关联的值?

I'm new to Coffeescript and I'm having issues resolving an issue. I have a JSON object that is currently stored in a variable. How do I iterate through the keys in the JSON object to display the key name and values associated with it?

if client
  result = JSON.parse client
  $.each result, (k, v) ->
    alert k + " is " + v

任何帮助将不胜感激。 >

Any help would be appreciated.

推荐答案

for key, value of result
  console.log "#{key} and #{value}"

#loops> docs#loops

more in the docs#loops

这篇关于如何使用coffeescript迭代JSON散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆