Strange characters in JSON (received after cURL auth)

This is the function that I use to capture the JSON file from the Feedbin API .

<?php error_reporting(E_ALL); // JSON URL which should be requested $json_url = 'https://api.feedbin.me/v2/entries.json'; $username = 'my_username'; // authentication $password = ' my_password'; // authentication // Initializing curl $ch = curl_init( $json_url ); // Configuring curl options $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => $username . ":" . $password // authentication ); // Setting curl options curl_setopt_array( $ch, $options ); // Getting results $result = curl_exec($ch); // Getting JSON result string print_r ($result); ?> 

The problem is that JSON I get a little .. weird. It has many characters like \ u003E \ u003C / a \ u003E \ u003C / p \ u003E \ n \ u003Cp \ u003E ... You can see the JSON here .

+4
source share
2 answers

When you call json_decode in PHP on strings containing these encodings, they will be correctly decoded. http://json.org/ lists \ufour-hex-digits as a valid character. No problems.

 $ echo json_decode('"\u003E\u003C/a\u003E\u003C/p\u003E\n\u003Cp\u003E"'); ></a></p> <p> 
+3
source

They are valid for unicode sequence. Here is a simple example

 $data = array( "abc" => 'åbcdéfg' ); // Encode $data = json_encode($data) . "\n"; // Output Value echo $data; // Output Decoded Value print_r(json_decode($data)); 

Output

 {"abc":"\u00e5bcd\u00e9fg"} stdClass Object ( [abc] => åbcdéfg ) 
+2
source

Source: https://habr.com/ru/post/1484883/


All Articles