我曾经从数据库中获取数据然后,我在Json中传递数据并将其推入数组以在Highcharts上使用。
现在,我有了一种从网络服务获取数据的新方法,而且我对如何传递数据非常困惑。
DATABASE的旧方式
[HttpGet]
public JsonResult EsperaHora(string data1, string data2, int? cliente)
{
var voiceData = new KiperVoiceData(cliente);
var media = voiceData.GetEsperaData(data1, data2);
var atend = voiceData.GetEsperaHora(data1, data2);
var result = new { atend, media };
return Json(result, JsonRequestBehavior.AllowGet);
}
ON JS文件
$.ajax({
url: '/KiperVoice/EsperaHora',
dataType: "json",
type: "GET",
data: { 'data1': data1, 'data2': data2, 'cliente': cliente },
success: function (data) {
var Categories = new Array();
var Series = new Array();
var Series2 = new Array();
var media = data.media;
var total = 0;
for (var i in data.atend) {
Categories.push(data.atend[i].Hora);
Series.push(data.atend[i].Espera);
Series2.push(data.atend[i].Qtde);
total += parseInt(data.atend[i].Qtde);
}
$('#media').val(media);
$('#total').val(total);
var HoraArray = JSON.parse(JSON.stringify(Categories));
atendHora(HoraArray, Series);
atendQtde(HoraArray, Series2);
}
},
它的工作非常好,但现在,我需要从Webservice Json获取de数据,如下所示:
Json的新方式
[HttpGet]
public JsonResult EsperaHora3(string data1, string data2, int? cliente)
{
string WEBSERVICE_URL = "http://187.49.236.29:3010/report/waithour?from=" + data1 + "&to=" + data2 + "&queue=Base";
var webRequest = WebRequest.Create(WEBSERVICE_URL);
if (webRequest != null)
{
webRequest.Method = "GET";
webRequest.Timeout = 20000;
webRequest.ContentType = "application/json";
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
{
var jsonResponse = JsonConvert.DeserializeObject<List<APIVoice>>(sr.ReadToEnd());
}
}
}
return Json(true, JsonRequestBehavior.AllowGet);
}
[{"key":"10:00","value":{"total":2,"avg":20}},
{"key":"11:00","value":{"total":4,"avg":25.5}},
{"key":"14:00","value":{"total":3,"avg":5.33}]
其中:
Key = Hora
Qtde = total
Espera = avg
答案 0 :(得分:0)
我找到了解决方案!!!
$.ajax({
url: '/KiperVoice/EsperaHora3',
dataType: "json",
type: "GET",
data: { 'data1': data1, 'data2': data2, 'cliente': cliente },
success: function (data) {
var Categories = new Array();
var Series = new Array();
var Series2 = new Array();
for (var i in data) {
Categories.push(data[i].Key);
Series.push(parseInt(data[i].value.avg));
Series2.push(data[i].value.total);
}
var HoraArray = JSON.parse(JSON.stringify(Categories));
atendHora(HoraArray, Series);
atendQtde(HoraArray, Series2);
}
},
我认为这是最神秘的!