Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将Json数据转换为数组_Javascript_Jquery_Json - Fatal编程技术网

Javascript 将Json数据转换为数组

Javascript 将Json数据转换为数组,javascript,jquery,json,Javascript,Jquery,Json,我有一个问题,我解释了我必须做的事情,我转换了json格式,如下所示: [ { "Latitude": "-7.00786", "Longitude": "34.99805", "UserID": 0, "HTMLCode": "<p><h3>Jhony Jhony</h3><br/><i>t would be title, info on the missiona

我有一个问题,我解释了我必须做的事情,我转换了json格式,如下所示:

[
    {
        "Latitude": "-7.00786",
        "Longitude": "34.99805",
        "UserID": 0,
        "HTMLCode": "<p><h3>Jhony Jhony</h3><br/><i>t would be title, info on the missionary and then links for any social links they have.  So in backend if they DO NOT have a twitter account then that icon would disappear.  It only shows the icons if it exists and they put in the info in the administrator backend.\r\nFor “Get Their Updates”.  It will ask for their email address and then email them a predetermined .pdf (which is set in admnistrator backend for that missionary).  Als</i><br/><i>Tanzania</i><br/><img src=/Content/SocialMediaImages/_facebook_btrix.png/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>"
    },
    {
        "Latitude": "46.91814",
        "Longitude": "25.62973",
        "UserID": 0,
        "HTMLCode": "<p><h3>Testing</h3><br/><i>Its a testing purposes only......</i><br/><i>Romania</i><br/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>"
    },
    {
        "Latitude": "29.54032",
        "Longitude": "83.51368",
        "UserID": 0,
        "HTMLCode": "<p><h3>Nayeem Mansoori</h3><br/><i>Description for testing</i><br/><i>China</i><br/><img src=/Content/SocialMediaImages/_facebook_btrix.png/><img src=/Content/SocialMediaImages/_googleplus_btrix.png/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>"
    }
]
[
{
“纬度”:“-7.00786”,
“经度”:“34.99805”,
“用户ID”:0,
“HTMLCode”:“Jhony Jhony
t将是标题、传教士的信息,然后是他们拥有的任何社交链接的链接。因此,在后端,如果他们没有twitter帐户,则该图标将消失。它仅显示存在的图标,并将信息放入管理员后端。\r\n“获取他们的更新”。它将询问他们的电子邮件地址,然后通过电子邮件向他们发送一个预先确定的.pdf文件(该文件在administrator后端为该传教士设置)。Als
坦桑尼亚
“ }, { “纬度”:“46.91814”, “经度”:“25.62973”, “用户ID”:0, “HTMLCode”:“测试
仅用于测试目的……”
罗马尼亚
“ }, { “纬度”:“29.54032”, “经度”:“83.51368”, “用户ID”:0, “HTMLCode”:“Nayeem Mansoori
测试说明
中国
” } ]
我想将此格式更改为数组,如下所示:

 var locations = [[-7.00786, 34.99805, 0, '<p><h3>Jhony Jhony</h3><br/><i>t would be title, info on the missionary and then links for any social links they have.  So in backend if they DO NOT have a twitter account then that icon would disappear.  It only shows the icons if it exists and they put in the info in the administrator backend.For “Get Their Updates”.  It will ask for their email address and then email them a predetermined .pdf (which is set in admnistrator backend for that missionary).  Als</i><br/><i>Tanzania</i><br/><img src=/Content/SocialMediaImages/_facebook_btrix.png/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>'], [46.91814, 25.62973, 0, '<p><h3>Testing</h3><br/><i>Its a testing purposes only......</i><br/><i>Romania</i><br/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>'], [29.54032, 83.51368, 0, '<p><h3>Nayeem Mansoori</h3><br/><i>Description for testing</i><br/><i>China</i><br/><img src=/Content/SocialMediaImages/_facebook_btrix.png/><img src=/Content/SocialMediaImages/_googleplus_btrix.png/><div id=div0 style=display:none><input type=text id=txt0 /><input type=button value=Submit class=btnGetUpdatesUsingEmail data-attr-id=#txt0 data-attr-UserId=0 /> </div><a href=0 class=GetUpdates>GetUpdates</a><p>']];
var locations=[[-7.00786,34.99805,0,”Jhony-Jhony
t将是标题、关于传教士的信息,然后是他们拥有的任何社交链接的链接。因此,在后端,如果他们没有twitter帐户,则该图标将消失。它仅显示存在的图标,并将其放入管理员后端的信息中。例如:“获取他们的更新”。它将询问他们的电子邮件地址,然后通过电子邮件向他们发送一个预先确定的.pdf文件(该文件在admistrator后端为该传教士设置)。Als
坦桑尼亚
,[46.91814,25.62973,0,,测试
仅用于测试,[29.54032,83.51368,0'Nayem Mansoori
测试说明
中国
'];

请帮助我,我也在用谷歌搜索,但没有任何结果。

您可以通过对象的键访问对象值,并将它们添加到数组中

var locations = [[
    json.Latitude,
    json.Longitude,
    json.UserID,
    json.HTMLCode
]];
请注意,您需要这样做,而不是在中使用类似于
for..的东西,因为JavaScript对象不是有序的,数组是有序的

编辑:我的原始答案是在呈现对象数组之前做出的。由于外部数组仍然是一个数组,所以您可以正常地迭代外部数组

var locations = [];
jsonArray.forEach(function (json) {
    locations.push([
        // see above
    ]);
});

这里有一个使用
map()的简单方法。


你真的有JSON,还是有JavaScript数组?我有JSON数据,但我想改成数组格式,比如[[-7.00786,34.99805,0,'nayeem']]你能简单解释一下原因吗?你现在的对象语法可能更方便、更容易理解。你为什么要这样做?
locations[0].HTMLCode
位置[0][3]可读性强得多
@Blazemonger我认为这样做的一个原因是,如果他需要通过
.apply
将值传递给函数,那么他需要一个具有正确参数顺序的数组。不过,我想不出其他情况,如果这里不是这样,那么我不确定你为什么要进行转换。用mappy替换每一个在迭代
json
时,不要依赖于键的顺序。这意味着您可以为两个类似的json blob获得不同的数组顺序。我无法理解bro@nayemmansooriit正在生成数组数组,我想,这就是您正在考虑的??其获取引用错误:jsonArray未定义
var array = []
$.each(json, function(index, value){
   var child =[];
   $.each(value,function(key,value){
      child.push(value);
  });
  array.push(child);
});
var locations = $.map(json, function(v,i){
    return [[v.Latitude, v.Longitude, v.UserID, v.HTMLCode]];
});