简体   繁体   中英

How to parse a string in json?

I have a string like this:

 0: array( 'name' => 'john', 'username' => 'foo' ) 1: array( 'name' => 'jack', 'username' => 'foo' )"

how I can encode it in json? I tried with:

$value = array_values($arr);
var_dump($value);

but I get NULL

UPDATE - If I do json_encode($arr); I get:

 ""\r\n 0: array(\r\n 'name' => 'john',\r\n 'username' => 'foo'\r\n )\r\n 1: array(\r\n 'name' => 'jack',\r\n 'username' => 'foo'\r\n )""

Take a look at json_encode php function. I believe this is what you're looking for.

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM