当前位置:网站首页>How to use JSON data format

How to use JSON data format

2022-06-23 17:48:00 It workers

json_encode() On variables JSON code

json_decode() Yes JSON Format of the string , Convert to PHP Variable

json_last_error Returns the last error that occurred

Resource type cannot be converted to json Format , Nor can it be converted to serialize data format , Similar to file identification .

Json Data format and serialize Similarities and differences of data formats

The same thing

1、 Is to convert other data types into a string that can be transferred

2、 It's all structural data

Difference

1、Serialize Serialized data format Save the original data type

2、JSON The data format should be more concise than Serialize Data format after serialization

Use scenarios :

1、JSON Suitable for large amount of data , It is not required to keep the original data type

2、Serialize Suitable for storing data strings with encryption , Prevent data from being intercepted, deserialized and cracked in the middle of the process

 <?php
 header("Content-type:text/html; charset=utf-8");  // Declaration code  
 
    function createHtmlTag($tag = ""){ 
 
            echo "$tag";  
    } 
 
    createHtmlTag("Www.aseoe.Com");  
 
    createHtmlTag("JSON and serialize  contrast "); 
 
    $member = array("site","tree");   // Define an array  
 
    var_dump($member);   // Print  
 
    $jsonObj = json_encode($member);  // It can be interpreted as json data format  
    $serializeObj = serialize($member);  // It can be interpreted as serialize data format  
 
    createHtmlTag($jsonObj);   // There is no need to save the data format  
    createHtmlTag($serializeObj);  // Can encrypt the transmitted data , Prevent interception  
?> 
原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201051804123294.html