0

我有一个如下所示的 CSV 文件:

http://ideone.com/YWuuWx

我读取了文件并将其转换为数组,这完全可以正常工作,但随后我将数组 json 化 -但 json_encode 没有输入真实值 - 它输入 null - 这是数组和 jsonized 数组的转储:

http://jave.jecool.net/stackoverflowdemos/csv_to_json_to_arraydump.php

我这样转换:$php_array= json_encode($json_array,JSON_PRETTY_PRINT);

任何人都知道可能导致问题的原因是什么?

编辑:我认为它有 90% 的可能性是由 latin1 字符引起的——有人知道最好的解决方法吗?

4

1 回答 1

2

Assuming that it is in fact an encoding error, and that your data is actually encoded in some ISO-8859 variant (I'm guessing latin2 rather than latin1 based on your use of LATIN SMALL LETTER R WITH CARON), and that it is CONSISTENTLY so, you can use iconv() to re-encode it as UTF-8 before doing json_encode():

$foo = iconv('ISO-8859-2', 'utf8', $foo);
于 2013-09-03T10:49:42.663 回答