次のJSONを返す.NETWebサービスがあります。
{"command":"getqcardjson","valuesets":[{"datatable":"eaa65990-8f88-45e0-966b-610858ad4cb6","values":[{"Id":"eaa65990-8f88-45e0-966b-610858ad4cb6","InternalName":"Alpha Profile","TableName":"Alpha Profile","OnMainMenu":"","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"","IsSchemaObject":"","IsSecured":"False","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"False","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"Information.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"This is a test Enquiry profile object called Alpha Profile","Caption":"Alpha Profile","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"2cbc4bc4-7db0-4344-b49a-bbc8ed4e9e60","InternalName":"CompMP","TableName":"CompMP","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"CompMP","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"f33038ce-2a64-4e79-99fc-ad6aaf90c2bb","InternalName":"ContactProfile","TableName":"ContactProfile","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"ContactProfile","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"fbb39ed3-0409-4712-b6dd-f6853b079aa6","InternalName":"QCardInqMP","TableName":"QCardInqMP","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.gif","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"QCardInqMP","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"41db39fb-fda8-4c5c-adc4-6e6c1ba77b90","InternalName":"QCEventAttendance","TableName":"QCEventAttendance","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"","IsChained":"","IncludeInGlobalSearch":"","IsModelObject":"","IsSchemaObject":"","IsSecured":"","IsFileNewMenu":"","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"","DefaultObjectLayoutStyle":"","Notes":"","Caption":"Attendance details","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"8f186be5-d0ec-4dc7-bfd5-9b9190644c1f","InternalName":"QCFilms","TableName":"QCFilms","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"","IsSchemaObject":"","IsSecured":"False","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"False","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"","DefaultObjectLayoutStyle":"2b69073c-4035-4597-acc0-4d8345ba9d1c","Notes":"","Caption":"QCFilms","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"False","IsGeocodable":"False"}]}]}
私のクライアントコードは次のとおりです。
$('#panelMiddle').append('Getting Json');
var url = "svc.asmx/GetJSONData?command=getqcardjson&qcardid=" + QCardId;
$.ajax({
url: url,
dataType: 'json',
success: function(data) {
$('#panelMiddle').append('Success');
},
complete: function() {
$('#panelMiddle').append('Completed');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('#panelMiddle').append(' #ERROR:' + textStatus + '# ' + errorThrown + ' ');
}
});
返されたJSONをhttp://www.jsonlint.com/に貼り付けると、検証されますが、jQueryAJAXはtextStatus="parsererror"とerrorThrown="InvalidJSON"でエラーを呼び出します。私のWebsvcは次のように定義されています。
[WebMethod(EnableSession = true)] // Required to create web service, even when json decoration present
[ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)] // Required decoration to ensure we can call using json
public string GetJSONData(string command)
{
誰が何が起こっているのか知っていますか?ありがとう。
Firefoxコンソールの応答は次のように表示されます。
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://highpersoft.com/">{"command":"getqcardjson","valuesets":[{"datatable":"eaa65990-8f88-45e0-966b-610858ad4cb6","values":[{"Id":"eaa65990-8f88-45e0-966b-610858ad4cb6","InternalName":"Alpha Profile","TableName":"Alpha Profile","OnMainMenu":"","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"","IsSchemaObject":"","IsSecured":"False","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"False","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"Information.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"This is a test Enquiry profile object called Alpha Profile","Caption":"Alpha Profile","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"2cbc4bc4-7db0-4344-b49a-bbc8ed4e9e60","InternalName":"CompMP","TableName":"CompMP","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"CompMP","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"f33038ce-2a64-4e79-99fc-ad6aaf90c2bb","InternalName":"ContactProfile","TableName":"ContactProfile","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.png","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"ContactProfile","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"fbb39ed3-0409-4712-b6dd-f6853b079aa6","InternalName":"QCardInqMP","TableName":"QCardInqMP","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"100","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"False","IsSchemaObject":"False","IsSecured":"","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"profile.gif","DefaultObjectLayoutStyle":"980163c2-2688-465d-9383-e5ad4dbf631f","Notes":"","Caption":"QCardInqMP","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"41db39fb-fda8-4c5c-adc4-6e6c1ba77b90","InternalName":"QCEventAttendance","TableName":"QCEventAttendance","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"","IsChained":"","IncludeInGlobalSearch":"","IsModelObject":"","IsSchemaObject":"","IsSecured":"","IsFileNewMenu":"","IsUpdateShouldRippleCache":"","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"","DefaultObjectLayoutStyle":"","Notes":"","Caption":"Attendance details","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"","IsGeocodable":""},{"Id":"8f186be5-d0ec-4dc7-bfd5-9b9190644c1f","InternalName":"QCFilms","TableName":"QCFilms","OnMainMenu":"True","DefaultDataSourceId":"bb4d1622-2e48-40b6-bea7-6355d701445c","DefaultOrder":"","IsChained":"","IncludeInGlobalSearch":"False","IsModelObject":"","IsSchemaObject":"","IsSecured":"False","IsFileNewMenu":"False","IsUpdateShouldRippleCache":"False","AdvancedSearchQueryId":"","CompoundViewQueryId":"","GlobalSearchQueryId":"","Icon":"","DefaultObjectLayoutStyle":"2b69073c-4035-4597-acc0-4d8345ba9d1c","Notes":"","Caption":"QCFilms","IsProfileObject":"True","ShortCacheQueryId":"","WorkflowForCreation":"","IsAllowNewFromExisting":"False","IsGeocodable":"False"}]}]}</string>
おそらくそれが問題です。上記のWebメソッド宣言に何か問題がありますか?
サーバーは現在これを行っています:{"メッセージ": "無効なJSONプリミティブ:getqcardjson。"、 "StackTrace": "at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\ r \ n at System.Web.Script.Serialization .JavaScriptObjectDeserializer.DeserializeInternal(Int32depth)\ r \ n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input、Int32depthLimit、JavaScriptSerializer serializer)\ r \ n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize (JavaScriptSerializerシリアライザー、文字列入力、タイプタイプ、Int32depthLimit)\ r \ n System.Web.Script.Services.RestHandler.GetRawParamsFromGetRequest(HttpContextコンテキスト、JavaScriptSerializerシリアライザー、WebServiceMethodData methodData)\ r \nSystem.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 "}