我的服务方式:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getDataFromTrainingMaster()
{
List<TrainingMasterDataStruct> results = new DAL().GetDataFromTrainingMaster();
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(results).ToString();
}
我的 .net Web 服务返回包装在 XML 中的 JSON,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/"> [{"Training_Code":"1234 ","Training_Duration":"2hrs ","Training_Startdate":"2/14/2013 3:00:00 PM","Training_Enddate":"2/14/2013 5:00:00 PM","Trainer_ID":1,"Training_Location":"B-Wing Training room-4","Comments":"C# training","Keyword":"C#1234","NumberofDays":1},{"Training_Code":"4321 ","Training_Duration":"16 ","Training_Startdate":"2/17/2013 10:30:00 AM","Training_Enddate":"2/17/2013 5:30:00 PM","Trainer_ID":2,"Training_Location":"A-Wing Training Room-6","Comments":"Objective-C","Keyword":"Obj-C4321","NumberofDays":2}]
我需要以下格式:
"Training":[{"Training_Code":"1234 ","Training_Duration":"2hrs ","Training_Startdate":"2/14/2013 3:00:00 PM","Training_Enddate":"2/14/2013 5:00:00 PM","Trainer_ID":1,"Training_Location":"B-Wing Training room-4","Comments":"C# training","Keyword":"C#1234","NumberofDays":1},{"Training_Code":"4321 ","Training_Duration":"16 ","Training_Startdate":"2/17/2013 10:30:00 AM","Training_Enddate":"2/17/2013 5:30:00 PM","Trainer_ID":2,"Training_Location":"A-Wing Training Room-6","Comments":"Objective-C","Keyword":"Obj-C4321","NumberofDays":2}]</string>
我怎样才能做到这一点?