How do I get the comments in a json string using php?
I have a php script that decodes data in a json string, but there is an additional small piece of metadata included as a comment in the first line of the string. I could split the string and get the first line, 开发者_JS百科and parse that with regex, but I'd rather use a native json function for getting the comments if it exists.
Anybody knows something like this?
The JSON specification does not allow for comments. If your data includes comments, then it is not JSON and a JSON parser should be expected to error on encountering them.
It sounds like you will have to preprocess your non-JSON data to split it into a JSON part and a comment part, then process the JSON part normally and the comment part with some custom code.
The JSON spec does not define comments, which means that your JSON string is not JSON. PHP thus has no native way to extract comments from json strings.
精彩评论