SQL query to Google's JSON format

柔情痞子 提交于 2019-12-23 06:22:56

问题


I have posted a code snippet a few days ago about this problem. I try to examine this problem from another side.

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

                    )

            )

    )

)

回答1:


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;
                }


来源:https://stackoverflow.com/questions/25358760/sql-query-to-googles-json-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!