rfc4627

Does JSON 'officially' Support Conversion of Native Types?

旧时模样 提交于 2019-12-11 01:18:03
问题 In PHP, you can use json_encode to encode an object as a json string. $string = json_encode($some_object); However, PHP has the standard slew of datatypes which are not considered objects (ints, strings, etc.) If you pass in a string to json_encode , this returns a string that contains a javascript statement that could be used to define the string. In less awkward phrasing, this echo json_encode("Hello world, please don't " . '"' . "misuse quote's for emphasis " . "or possessive apostrophes'

Can an array be top-level JSON-text?

Deadly 提交于 2019-11-26 09:31:14
问题 per the debate in this post: json-conversion-in-javascript 回答1: Yes, an array is legal as top-level JSON-text. There are three standard documents defining JSON: RFC 4627, RFC 7159 (which obsoletes RFC 4627), and ECMA-404. They differ in which top-level elements they allow, but all allow an object or an array as the top-level element. RFC 4627: Object or array. "A JSON text is a serialized object or array." RFC 7159: Any JSON value. "A JSON text is a serialized value." ECMA-404: Any JSON value