开发者

php array output

I am not a php guy, so I have a small question for all the php devs out there.

I am building a java application which calls a php webservice. The php web service has a login method which takes user_auth and application_name as parameters. user_auth is an array which has thr开发者_开发知识库ee strings username, password and version number.

Can anyone tell me which of the below java strings match the array output when we print it?

1) String user = "user_auth{username=will; password=18218139eec55d83cf82679934e5cd75; version=1.0;}";
2) String user = "{'user_auth':{'username':'will','password':'18218139eec55d83cf82679934e5cd75', 'version':'1.0'}}";

Thanks, aspr


You can any of these formats

$user = array('user_auth' =>
    array('username' => 'will'),
    array('password' => '18218139eec55d83cf82679934e5cd75'),
    array('version' => '1.0'),
);

var_dump(serialize($user)); // use unserialize to decode
var_dump(json_encode($user)); // use json_decode to decode

You any of these formats

String user = 'a:3:{s:9:"user_auth";a:1:{s:8:"username";s:4:"will";}i:0;a:1:{s:8:"password";s:32:"18218139eec55d83cf82679934e5cd75";}i:1;a:1:{s:7:"version";s:3:"1.0";}}' (length=153)
String user = '{"user_auth":{"username":"will"},"0":{"password":"18218139eec55d83cf82679934e5cd75"},"1":{"version":"1.0"}}' (length=107)


This looks like JSON (passing PHP arrays in a URL would not make much sense), but you need to use double quotes (") instead of single quotes ('), using your second example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜