English 中文(简体)
网络服务电话和JSON阵列的操纵
原标题:web service call and JSON array manipulation in javascript

我需要把一个网络服务从“javascript”上调,以以下格式填回“JSON”阵列:

["hello","there","I","am","an","array"]

不幸的是,用javascript Library I m(Sencha Touch)将这一数据装入植被,并不接受这种格式作为数据输入。 但它将为此而努力:

[["hello"],["there"],["I"],["am"],["an"],["array"]]

因此,这里有两个问题,即我如何能够把网络服务称作“javascript”,然后将返回阵列操纵为我所需要的格式? 我先看一下“ j子”方法,看不出这是否为走路,或者是否有更好的办法。

提供JSON阵列的URL是:

最佳回答

这里是一片 j,显示你所询问的两部分内容。 我用j Query来打我的美国宇宙航空研究开发机构电话(在支那支 j中ak)和Im使用斜线。 j 操纵:

http://jsfiddle.net/JohnMunsch/E7YTQ/

// Part 1: Get the raw data. Unfortunately, within a jsFiddle I can t go get it from a different domain. So I m
// simulating the call instead.
var rawDataPromise = $.ajax({
    url : "/echo/json/",
    data : fakeData,
    type : "POST"
});
// var rawDataPromise = $.ajax("http://fastmotorcycleservice.cloudapp.net/FastMotorCycleListService.svc/list/Bruno");

rawDataPromise.done(
  function (results) {
    // Part 2: Manipulate the data into the form we need.
    var manipulatedResults = _.map(results, function (item) { return [ item ]; });

    console.log(manipulatedResults);
  }
);

// You could also pull that together into a single call $.ajax(...).done(function (results) { ... });
问题回答

一俟你掌握当地变量之一的数据,你就可以按照你的愿望加以操纵:

var data = the_function_you_use_to_get_data();
var formatted_array = new Array();
for(i in data){
    var d = new Array();
    d[0] = i;
    formatted_array.push(d);
}

i 希望它回答你的问题





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签