产生json的哈希结构是什么? [英] what is the hash structure to produce json?

查看:133
本文介绍了产生json的哈希结构是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我传递给javascript的最终json示例.我将使用( yajl )ruby库从哈希中创建此json.

Below is a sample of final json I pass to javascript. I will use the (yajl) ruby library to create this json from a hash.

问题是产生以下json的红宝石哈希应该是什么样的?

The question is what should a ruby hash that produces the json below look like?

var data = [{
       data: "basics",
       attr: {},
        children: [
         {data: "login", attr: {run: "run"},
           children: [                   
           {data: "login", attr: {}}
          ]
         } ,
         {data: "Academic Year", attr: {run: "run"},
          children: [                   
           {data: "login", attr: {}},
           {data: "Academic Year", attr: {filter: "mini", SOF: "yes"}}
          ]

         }
        ]
      }];

推荐答案

您的问题不太清楚.您的意思是什么将创建您在问题中显示的JSON的Ruby结构?

Your question is not too clear. Do you mean what is the Ruby structure that would create the JSON you show in your question?

如果是这样,那么就开始....请注意,基本级别结构是Ruby Array,因为您的JSON基本级别结构也是Array.

If so, then here you go.... Note that the base-level structure is a Ruby Array because your JSON base level structure is also an Array.

mydata = [{
           'data' => "basics",
           'attr' => {},
           'children' => [{
                          'data' => "login",
                          'attr' => {'run' => "run"},
                          'children' => [{
                                         'data' => "login",
                                         'attr' => {}
                                        }]
                          },
                          {
                           'data' => "Academic Year",
                           'attr' => {'run' => "run"},
                           'children' => [{
                                          'data' => "login",
                                          'attr' => {}
                                          },
                                          {
                                           'data' => "Academic Year",
                                           'attr' => {'filter' => "mini", 
                                                      'SOF' => "yes"}
                                          }]
                           }]
         }]

这篇关于产生json的哈希结构是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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