SQL查询转换为Google的JSON格式 [英] SQL query to Google's JSON format
问题描述
几天前,我发布了一段代码段,介绍此问题。我尝试从另一方面检查这个问题。
I have posted a code snippet a few days ago about this problem. I try to examine this problem from another side.
所以,我有一个查询,我想从它的填充json文件输出。它包含更多的记录,而不仅仅是一个。问题是,我发现/我写的所有代码都只将第一条记录粘贴到带有列的文件中。我认为目前还没有关于这个问题的教程。
So, I have a query and I would like to fill in a json file from its output. It contains more records, not only one. The problem is, that all the code, that I have found / I have wrote paste only the first record into the file with the cols. I think there is no existing tutorial about this problem.
更新:示例输出:
UPDATE: Sample output:
Array (
[cols] => Array
(
[0] => Array
(
[id] =>
[label] => Name
[pattern] =>
[type] => string
)
[1] => Array
(
[id] =>
[label] => Start
[pattern] =>
[type] => date
)
[2] => Array
(
[id] =>
[label] => End
[pattern] =>
[type] => date
)
)
[rows] => Array
(
[0] => Array
(
[c] => Array
(
[0] => Array
(
[v] => X
)
[1] => Array
(
[v] => Date(2014,08,18,21,00,00)
)
[2] => Array
(
[v] => Date(2014,08,18,23,00,00)
)
)
)
[1] => Array
(
[c] => Array
(
[0] => Array
(
[v] => Y
)
[1] => Array
(
[v] => Date(2014,08,18,21,00,00)
)
[2] => Array
(
[v] => Date(2014,08,18,22,00,00)
)
)
)
[2] => Array
(
[c] => Array
(
[0] => Array
(
[v] => Z
)
[1] => Array
(
[v] => Date(2014,08,18,23,00,00)
)
[2] => Array
(
[v] => Date(2014,08,18,23,30,00)
)
)
)
)
)
推荐答案
解决方案:
这是一个字符编码问题,使用json_last_error()方法检测到:
Solution: It was a character encoding problem, that can be detected with json_last_error() method:
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
这篇关于SQL查询转换为Google的JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!