Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rails 3和PHP的合作问题_Php_Ruby On Rails_Ruby On Rails 3_Character Encoding - Fatal编程技术网

Rails 3和PHP的合作问题

Rails 3和PHP的合作问题,php,ruby-on-rails,ruby-on-rails-3,character-encoding,Php,Ruby On Rails,Ruby On Rails 3,Character Encoding,我正在尝试使用php5编写服务,并使用Rails 3使用它。 这就是我要做的 PHP: // $DATA is an associative array that contains an Ukrainian characters. // I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function header('Content-Type: json; charse

我正在尝试使用php5编写服务,并使用Rails 3使用它。
这就是我要做的

PHP:

// $DATA is an associative array that contains an Ukrainian characters.
// I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function

header('Content-Type: json; charset=utf8');
echo json_encode($DATA);
exit;
url = URI.parse("http://127.0.0.1/searchInvStat/showclaimdetails.php?app_n=#{@claim.claim_db[:app_number]}")
req = Net::HTTP::Get.new(url.request_uri)
res = Net::HTTP.start(url.host, url.port) {|http|
   http.request(req)
}

@states = ActiveSupport::JSON.decode( res.body )
PHP转换字符串,如\u00ca\u00e2\u00e8\u00f2\u00e0\u00ed\u00f6\u00b3\u00ff

轨道:

// $DATA is an associative array that contains an Ukrainian characters.
// I am converting all of values with Ukrainien characters to utf-8 using **utf8_encode** function

header('Content-Type: json; charset=utf8');
echo json_encode($DATA);
exit;
url = URI.parse("http://127.0.0.1/searchInvStat/showclaimdetails.php?app_n=#{@claim.claim_db[:app_number]}")
req = Net::HTTP::Get.new(url.request_uri)
res = Net::HTTP.start(url.host, url.port) {|http|
   http.request(req)
}

@states = ActiveSupport::JSON.decode( res.body )
但在结果页面上,我得到了一个字符串,比如Îèñèèèèèèèèèèèèèèèèèóèè


有人能帮我吗

我找到了解决方案:


不要使用
json\u encode($DATA)
你应该使用
iconv(“windows-1251”,“UTF-8”,“$DATA['OUTDOCS'][$i]['regNumb'])

如果在浏览器中打开PHP脚本会发生什么?看起来还好吗?是的,我想是的,我看到了u00ca\u00e2\u00e8\u00f2\u00e0\u00ed\u00f6\u00b3\u00ff字符串,我想没问题