小编And*_*rew的帖子

字符串不匹配错误

我想从我的另一个网站解析一些项目.当我添加一个字符串

t.body["Some text"] = "Other text"
Run Code Online (Sandbox Code Playgroud)

它取代了正文中的一些文字,出现了错误:

IndexError in sync itemsController#syncitem

string not matched
Run Code Online (Sandbox Code Playgroud)

LIB/sync_items.rb

require 'net/http'
require 'json'
require 'uri'


module ActiveSupport
  module JSON
    def self.decode(json)
      ::JSON.parse(json)
    end
  end
end
module SyncItem
  def self.run

   uri = URI("http://example.com/api/v1/pages")
   http = Net::HTTP.new(uri.host, uri.port)
   request = Net::HTTP::Get.new(uri.request_uri)
   response = http.request(request)

   parsed_response = JSON.parse(response.body)
     parsed_response.each do |item|
      t = Page.new(:title => item["title"], :body => item["body"], :format_type => item["format_type"])     
      t.body["Some text"] = "Other text"    
      t.save
   end
  end    
end
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

ruby console parsing json ruby-on-rails

0
推荐指数
1
解决办法
2585
查看次数

标签 统计

console ×1

json ×1

parsing ×1

ruby ×1

ruby-on-rails ×1