我正在尝试将 json 对象发送到 Web 服务,以将其反序列化为自定义 (LineItemWithDetails) 对象。当传递给 Web 服务的 json 中的任何位置有撇号时,我会收到以下错误。在本例中,它是“BudgetJustification”。我不知道我应该在这里做什么。
$.ajax({
type: "POST",
url: baseUrl + "/WebService/BudgetGrid.asmx/SaveLineItemDetails",
data: "{details: '" + JSON.stringify(_lineItemObj) + "', categoryId: " + _lineItemObj.LineItem.CategoryID + ", lineItemId: " + _lineItemObj.LineItem.ID + " }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function (response) {
},
error:
function (response) {
ShowError(response.responseText);
}
});
[WebMethod(true)]
public string SaveLineItemDetails(string details, int categoryId, int lineItemId)
{
PersistantData session = PersistantData.getInstance();
BudgetBase budgetBase = BudgetFactory.Retrieve((BudgetTypes)categoryId, session.GranteeID, session.GrantID, session.BudgetYear, session.BatchVersion, session.SourceID, session.ApplicationID, session.OriginID, session.BudgetChangeRequestFundingType, session.BatchID, session.UserID);
JavaScriptSerializer serializer = new JavaScriptSerializer();
Gov.Grants.Budget.Business.LineItem.LineItemWithDetails d = serializer.Deserialize<Gov.Grants.Budget.Business.LineItem.LineItemWithDetails>(details);
budgetBase.SaveDetails(d, lineItemId);
return "";
}
错误信息
"{"Message":"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. (428): {details: \u0027{\"LineItem\":{\"ID\":18494,\"ParentID\":18487,\"ApplicationID\":0,\"GranteeID\":57,\"BudgetYear\":2011,\"LineItemTypeID\":3,\"CategoryID\":3,\"CategoryName\":\"Travel\",\"VersionID\":0,\"OriginID\":2,\"AmtChange\":0,\"LineItemGuid\":\"fab8d064-767b-4526-8762-81a849361551\",\"Description\":\"PHIN conference - 1 + Trip(s) + [Out of State]\",\"ExceptionText\":\"Other: Out of state travel costs ($1,970) are restricted to NIC, Hepatitis B Coordinators\u0027 Meeting, Program Managers/PHA Meeting, ACIP meetings, VFC and AFIX training, and other CDC-sponsored immunization program meetings. \",\"DiffGram\":\"FA Travel Line Item Needs More Information.\",\"UserID\":452,\"AllocID\":57695,\"AllocGuid\":\"00000000-0000-0000-0000-000000000000\",\"IsReviewedLI\":true,\"NMIStatusID\":1,\"NMIStatus\":\"Not Addressed\"},\"Details\":{\"Location\":\"PHIN conference\",\"NumTrips\":1,\"NumPeople\":\"5\",\"NumDays\":5,\"AmtPerDi
em\":56,\"NumNights\":4,\"AmtLodging\":150,\"AmtAir\":850,\"AmtOther\":240,\"NumMiles\":0,\"AmtMileage\":0.405,\"TravelTypeID\":2,\"TravelTypes\":[{\"LookupName\":\"TravelType\",\"Lookup_ID\":1,\"BudgetYear\":-1,\"LookupValue\":\"In State\",\"LookupKey\":\"\",\"LookupCode\":\"\",\"LookupText\":\"\"},{\"LookupName\":\"TravelType\",\"Lookup_ID\":2,\"BudgetYear\":-1,\"LookupValue\":\"Out of State\",\"LookupKey\":\"\",\"LookupCode\":\"\",\"LookupText\":\"\"}],\"DefaultNumOfMonth\":12,\"BudgetJustification\":\"This is the annual Public Health Information Network Conference. This is attended by the WVSIIS manager or designee to keep abreast with what\u0027s going on with PHIN, CRA and other public health applications and directions.\",\"Identifier\":\"PHIN\",\"CategoryConfig\":null}}\u0027, categoryId: 3, lineItemId: 18494 }","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.Deseria
lizeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}"