WinJS OData JSON

让人想犯罪 __ 提交于 2019-11-28 11:55:58

问题


try to send data to my database by web service an get this error:

Primitive values of type 'Edm.Decimal' and 'Edm.Int64' must be quoted in the payload. Make sure the value is quoted

here is my code:

var newEntry = {
        datum: entryDate,
        monat: parseFloat(entryMonth),
        taetigkeit: document.getElementById("addWork").value,
        total: parseFloat(document.getElementById("addTotal").value),
        totalV: parseFloat(document.getElementById("addTotalV").value),
        in_auswertung: 0,
        teil_projekt_id: parseFloat(document.getElementById("addSubProject").value),
        projekt_id: parseFloat(document.getElementById("addProject").value),
        TimeStamp: entryDate,
        sAuftraggeber: document.getElementById("addContractor").value,
        iidBenutzer: parseFloat(298),//sessionStorage.getItem("userId"),
        akt_id: parseFloat(document.getElementById("addActivity").value)
    };

    WinJS.xhr({
        type: "post",
        url: requestUrl,
        data: JSON.stringify(newEntry),
        headers: {
            "Content-type": "application/json"
        }

    }).then(
          function complete(response) {

          },

Thanks Marlowe


回答1:


At least one of your properties has a declared type of Edm.Decimal or Edm.Int64. These values must be serialized as a string (i.e., the number wrapped in " characters) in OData's JSON format. If you're not sure what the declared types of the properties are, you can look up the entity type in the server's $metadata document (typically available at http://.../MyService.svc/$metadata).

So, for the property or properties that are Edm.Int64 or Edm.Decimal, you could remove the call to parseFloat() and just keep it as a string.



来源:https://stackoverflow.com/questions/16544469/winjs-odata-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!