需要帮助解析JSON

时间:2011-05-23 12:09:27

标签: ruby json parsing

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的值..

1 个答案:

答案 0 :(得分:1)

试试这个..

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