我正在尝试使用从Java脚本到我的WCF oData服务的PUT请求更新数据库中记录的单个值。调用服务的代码是
var upda = { stat: $("#com_status_txt").val() };
upda = JSON.stringify(upda);
console.log(upda);
$.ajax({
type: "PUT",
contentType: "application/json; charset=utf-8",
url: "http://localhost:65401/sdrservice.svc/issues('" + sessionStorage.currentIssue + "')/stat",
data: upda,
dataType: "json",
success: function (result) {
//Some code goes here...
},
error: function (xhr, textStatus, errorMessage) {
console.log(JSON.stringify(xhr));
}
});
其中 sessionStorage.currentIssue 是我的问题ID,我需要更新表格中的 stat 字段。
但是当我运行此服务时,我收到以下错误。
{"readyState":4,"responseText":"{\"odata.error\":{\"code\":\"\",\"message\":
{\"lang\":\"en-US\",\"value\":\"An error occurred while processing this
request.\"},\"innererror\":{\"message\":\"A top-level property with name 'stat'
was found in the payload; however, property and collection payloads must always
have a top-level property with name value' .
\",\"type\":\"Microsoft.Data.OData.ODataException\",\"stacktrace\":\" at
Microsoft.Data.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.
<>c__DisplayClassc.ReadTopLevelPropertyImplementation>b__5(PropertyParsingResult propertyParsingResult, String propertyName)\\r\\n at
Microsoft.Data.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(Duplic
atePropertyNamesChecker duplicatePropertyNamesChecker, Func`2
readPropertyAnnotationValue, Action`2 handleProperty)\\r\\n at
Microsoft.Data.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadTo
pLevelPropertyImplementation(IEdmTypeReference expectedPropertyTypeReference, DuplicatePropertyName
此处消息在有效负载中找到名为'stat'的顶级属性;但是,当我没有传递任何集合只是一个键/值对时,属性和集合有效负载必须始终具有名称值为“”的顶级属性。我的数据的json表示是
{"stat":"Query"}
答案 0 :(得分:0)
Json表示是一个问题,将其更改为
{“value”:“查询”}