小编典典

通过SQL查询Google的JSON格式

sql

所以
,我有一个查询,我想从其输出中填充一个json文件。它包含更多的记录,而不仅仅是一个。问题是,我找到的所有代码/我写的所有代码仅将第一个记录粘贴到带有cols的文件中。我认为没有有关此问题的现有教程。

更新: 示例输出:

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)
                            )

                    )

            )

    )

)

阅读 178

收藏
2021-05-16

共1个答案

小编典典

解决方案: 这是一个字符编码问题,可以使用json_last_error()方法检测到:

                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;
                }
2021-05-16