我试图通过使用json_encode将数组从PHP传递到javascript
但当我提醒值时,我只看到"对象对象等"
当我var_dump它我看到实际的数组但它没有在警报中显示它们
任何帮助,将不胜感激
问候
这是var_dump
array(1) {
[0]=>
array(2) {
["id"]=>
string(19) "3.0268"
["postcode"]=>
string(137) "hello"
}
}
array(2) {
[0]=>
array(2) {
["id"]=>
string(19) "3.0268070455319E+17"
["postcode"]=>
string(137) "ECMWF continues its flip-flopping, still a temp drop next week & #snow risk but then no rise, http://t.co/tBlg9Ihs #ukweather #uksnow"
Run Code Online (Sandbox Code Playgroud)
代码
<?php
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM address");
$arr = array();
while($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
?>
<script>
var test = <?php …
Run Code Online (Sandbox Code Playgroud) 我想遍历我的数据并做一些事情。
下列的
var stuff = JSON.stringify(data)
Run Code Online (Sandbox Code Playgroud)
返回我这样的东西:
{"0":"data:image/png;base64,testi,"2":"data:image/png;base64, testi2, ....
Run Code Online (Sandbox Code Playgroud)
我需要循环遍历,但我所做的方法不起作用。
for (var i = 0; i < stuff.length; i++) {
$('#img-thumb-id'+i).attr('src', data[i]);
}
Run Code Online (Sandbox Code Playgroud)
编辑
我正在使用JSON.stringify
是因为console.log(data)
刚刚返回了我无法使用的对象对象。
当我想要反序列化json时,我目前遇到了这个问题.我不知道如何使用未知键进行此操作
[
{
"84.200.222.4": [
0.022
]
},
{
"84.200.230.82": [
1.315
]
},
{
"80.156.160.161": [
0.874
]
},
{
"72.14.217.108": [
0.662
]
},
{
"108.170.251.193": [
0.638
]
},
{
"216.239.54.61": [
0.64
]
},
{
"172.217.23.131": [
0.564
]
}
]
Run Code Online (Sandbox Code Playgroud)
我什么时候想要这样做呢?
1. 84.200.222.4
- 0.022
2. 84.200.230.82
- 1,315
3. 80.156.160.161
- 0.874
4 72.14.217.108
- 0.662
Run Code Online (Sandbox Code Playgroud)
等等..我目前还不确定如何循环通过未知密钥是可能的?
所以我试图将此 json 数据解析为我网站上的列表。不过我似乎无法循环。我在网上查了一下,似乎没有什么作用......
json数据:
{"amount":4998,"users":[{"id":"765","username":"test","profileURL":"http://example.com","avatarURL":"http:///example.com"},{"id":"765","username":"test","profileURL":"http://example.com","avatarURL":"http://example.com"}]}
Run Code Online (Sandbox Code Playgroud)
我想循环用户然后获取 id、用户名等...
var jsonObj = [
{
"key1": "value1",
"key2": "value2",
"key3?": "value3"
},
{
"key1": "value1",
"key2": "value2",
"key3?": "value3"
}
];
Run Code Online (Sandbox Code Playgroud)
我想更新所有对象的所有值。这里的键和值是动态的,而不是 key1 和 value1。你能帮忙弄清楚它的要求吗?
我想让每个对象的每个值都变成“changedvalue”。所以更新jsonObj后的最终结果是
[
{
"key1": "changedvalue",
"key2": "changedvalue",
"key3?": "changedvalue"
},
{
"key1": "changedvalue",
"key2": "changedvalue",
"key3?": "changedvalue"
}
];
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数据结构。它基本上是一个对象数组。
const dataset = [
{
a: { total: 2, name: "red" },
b: { total: 3, name: "gold" },
c: { total: 6, name: "rose" },
},
{
a: { total: 10, name: "red" },
b: { total: 7, name: "purple" },
},
{
a: { total: 1, name: "pink" },
b: { total: 14, name: "blue" },
c: { total: 10, name: "rose" },
},
{
b: { total: 2, name: "green" },
c: { total: 18, name: …
Run Code Online (Sandbox Code Playgroud)