2017-01-23 38 views
0

我有一個由PHP應用程序生成的JSON哈希,我想在我的軌道控制器中讀取它。 有沒有什麼辦法可以再次將這個json轉換成哈希值,這樣我就可以讀取它。如何在Ruby中讀取PHP生成的json 1.8.7

json_from_php = "{'coms':[{'com':{'title':'kk dd','guid':'http:\/\/tes.name\/?p=02'}},{'com':{'title':'sdsdsdsd dsds','guid':'http:\/\/tes.name\/?p=06'}},{'com':{'title':'PHPTVDB: Using PHP ','guid':'http:\/\/tes.name\/?p=4'}},{'com':{'title':'Plugins','guid':'http:\/\/tes.name\/?p=08'}},{'com':{'title':'vvv','guid':'http:\/\/tes.name\/?p=2218'}},{'com':{'title':'dsds sdsds ','guid':'http:\/\/tes.name\/?p=12'}},{'com':{'title':'Represent ','guid':'http:\/\/tes.name\/?p=5'}},{'com':{'title':'ZebraTable','guid':'http:\/\/tes.name\/?page_id=4'}},{'com':{'title':'rr Plugin','guid':'http:\/\/tes.name\/?p=2'}},{'com':{'title':'dasd asdasd !','guid':'http:\/\/tes.name\/?p=1'}}]}" 

#ss = JSON.parser(json_from_php) 

錯誤信息: JSON :: ParserError(757:在 '{' COMS意外的標記 ':[{' COM「:{

參考https://davidwalsh.name/web-service-php-mysql-xml-json

回答

0
ss = ActiveSupport::JSON.decode(json_from_php) solved this issue