【问题标题】:Need help in parsing the JSON在解析 JSON 时需要帮助
【发布时间】:2011-05-23 12:09:26
【问题描述】:
response = Typhoeus::Request.get(API_SERVER_ADDRESS + "users/" + params[:id] +"/friends" + API_OAUTH_TOKEN)
@parsed_json = ActiveSupport::JSON.decode(response.body)

 @parsed_json['get.friendlist']["friendslist"].each do |first_name, last_name|
 p first_name
 end

Json 格式:-

    {
        -get.friendlist: {
            -friendslist: [
            -{
                id: "6"
                first_name: "Jeyaprabhu"
                last_name: "Palanichamy"
                im_screen_name: ""
                email: "Jeyaprabu@abc.net"
                password: "c4cce19cf6453c10754339a15cf9265d"
                mobile: ""
                date_of_birth: ""
                gender: "male"

            }
            -{
                id: "72"
                first_name: "Saravanan"
                last_name: "R"
                im_screen_name: "Saravanan R"
                email: "r.saravanan@abc.net"
                password: "7cc2f5546b199421184a287bb75c406d"
                mobile: ""
                date_of_birth: "9/9/1985"
                gender: "male"


            }
            ]
        }
    }

它没有打印 first_name 的值..

【问题讨论】:

  • 有什么问题?什么不工作?您希望代码做什么,它实际上在做什么?
  • @Matt Ball 它没有打印 First_name 的值..

标签: ruby json parsing


【解决方案1】:

试试这个..

<% @parsed_json['get.friendlist']["friendslist"].each do |json_output| %>
  <%=  json_output['first_name'] %>
<% end %>

【讨论】:

    猜你喜欢
    • 2017-09-10
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多