Нужно заполнить данными из ajax запроса jqGrid.
Но проблема с парсингом.
$(document).ready(function () {
$.ajax({
type: "POST",
url: "WebServiceMonitoringLog.asmx/Stations",
data: "{}",
contentType: 'text/json;charset=UTF-8',
dataType: "json",
success: succ,
error: err
});
function err(data, request, status) { alert('------\n' + data.responseText + '\n------'+'\n'+request+'\n'+status);}
function succ(data, status) {
jQuery("#addtree").jqGrid({
url: 'WebServiceMonitoringLog.asmx/Stations',
datatype: 'json',
mtype: "POST",
colNames: ['Id', 'Name', 'Coord'],
colModel: [
{name: 'Id',index: 'Id',width: 20,editable: false,},
{name: 'Name',index: 'Name',width: 150,align: "left",editable: false,size: 100},
{name: 'Coord',index: 'Coord',width: 100,editable: false,}],
rowNum: 10,
rowList: [2, 5, 10, 15],
pager: '#pjmap',
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
jsonReader: {repeatitems: false},
width: 600,
caption: 'jqGrid demo',
height: '100%',});
}
})
При выполнении вызывается функция err
Как видно-ошибка парсинга.
Код веб сервиса,откуда приходит ответ на ajax запрос
Код:
|
using System;
....................
using System.Collections.Generic;
namespace Example
{
class Station
{
public int Id{get;set;}
public string Name{get;set;}
public string Coord{get;set;}
public Station()
{
Id = 1;
Name = "st1";
Coord = "0;0";
}
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebServiceMonitoringLog : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Stations()
{
List<vStation> sl = new List<vStation>(DataManager.vStation.GetAllStation().Take(10));
List<Station> stl = new List<Station>();
for (int i = 0; i < sl.Count; i++)
{
stl.Add(new Station());
stl[i].Id = sl[i].StationId;
stl[i].Name = sl[i].NameStation;
stl[i].Coord = sl[i].Position.ToString();
}
var vsl = stl;
var gridData = new
{
total = 1,
page = 1,
records = vsl.Count,
rows = vsl,
};
var jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(gridData);
}
}
}
} |
Можно ли как нибудь убрать из ответа это:
Код:
|
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">
json-строка
</string> |
Чтобы осталасть только json-строка. Или я не правильно понимаю мысла парсинга ответа?