JSON到PHP关联数组 [英] JSON to PHP Associative array
问题描述
json_decode
,但发现它不是很有帮助。 这是我需要放入关联数组的数据:
{
data:[
{
name:Joe Bloggs,
id 203403465
},
{
name:Fred Bloggs,
id:254706567
},
{
name:Barny Rubble,
id:453363843
},
{
name:Homer Simpson,
id:263508546
}
]
}
< hr>
编辑:
在我接受答案后,我记得为什么我认为json_decode不起作用。
而不是使用关联这样的数组:
[0] => Array
(
[name] => Joe Bloggs
[id] => 203403465
)
我想要这样一个:
Array
(
[Joe Bloggs] => 45203340465
[Fred Bloggs] => 65034033446
)
不幸的是,我当时忘了这个..但是我现在解决了我的问题。
感谢您的帮助!
json来自ajax ....(否则代码与json_decode一起使用)
所以要确保js json stringifys你的对象和
你需要在json_decode之前的striplashes ;-)在php中
would any of you know a good way to put this into an associative array . I have tried json_decode
but found it to not be much help.
This is the data i need to put into an associative array:
{
"data": [
{
"name": "Joe Bloggs",
"id": "203403465"
},
{
"name": "Fred Bloggs",
"id": "254706567"
},
{
"name": "Barny Rubble",
"id": "453363843"
},
{
"name": "Homer Simpson",
"id": "263508546"
}
]
}
EDIT:
After I accepted the answer, I remembered why I thought that the json_decode wasn't working.
Instead of having an associative array like this:
[0] => Array
(
[name] => Joe Bloggs
[id] => 203403465
)
I wanted one like this:
Array
(
[Joe Bloggs] => 45203340465
[Fred Bloggs] => 65034033446
)
Unfortunately, I had forgotten this at the time.. but I have resolved my issue now anyway.
Thanks for all of your help!
i asume your json comes via ajax.... (otherwise the code works with json_decode) so be sure the js json stringifys your object and
you'll need to stripslashes before json_decode ;-) in php
这篇关于JSON到PHP关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!