简体   繁体   English

如何在Rails中将JSON数据转换为PList数据?

[英]How can I convert JSON data to PList data in Rails?

I am querying an external service which is passing back JSON data. 我正在查询传回JSON数据的外部服务。 I'd like to format this data as a binary PList to send it out to clients. 我想将此数据格式化为二进制PList,以将其发送给客户端。 How can I do that conversion in Rails? 如何在Rails中进行转换? This is a complex data structure with arrays & hashes as well as strings & integers. 这是一个复杂的数据结构,具有数组和散列以及字符串和整数。

Based on the comment, I am trying this: 根据评论,我正在尝试:

def friends_facebook
  @graph = Koala::Facebook::GraphAPI.new(current_user.facebook_token.token)
  render :plist => JSON.parse(@graph.get_connections("me", "friends").to_json)
end

Which results in the error (on the render line): 导致错误(在渲染行上):

incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)

Using http://plist.rubyforge.org/ and http://flori.github.com/json/ : 使用http://plist.rubyforge.org/http://flori.github.com/json/

JSON.parse(input).to_plist

You might have to write your own to_plist_node method(s) for your data structure(s). 您可能必须为数据结构编写自己的to_plist_node方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM