PHP到JSON格式 [英] PHP to JSON format
本文介绍了PHP到JSON格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的JSON格式是:
The JSON format I am getting is:
{
"test":[
{"key1":"value1"},
{"key2":"value2"}
]
}
但是有可能获得这种格式吗?
But is it possible to get this format instead?
{
"test": {
"key1":"value1",
"key2":"value2"
}
}
我的php代码是这样的:
My php code is this:
$key=$row[1];
$value=$row[2];
$posts[] = array($key => $value);
$response['strings'] = $posts;
fwrite($out, json_Encode($response))
我已经坚持了几个小时,请有人帮忙!预先感谢!
I've been stuck on this for hours, someone please help! Thanks in advance!
推荐答案
您要
$posts[$key] = $value;
问题在于,带有字符串键的PHP数组是JSON术语的对象.
The issue is that PHP arrays with string keys are objects in JSON terms.
这篇关于PHP到JSON格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文