WinJS OData JSON [英] WinJS OData JSON

查看:73
本文介绍了WinJS OData JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过Web服务将数据发送到我的数据库并得到以下错误:

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

这是我的代码:

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) {

          },

谢谢 马洛

推荐答案

您的至少一个属性的声明类型为Edm.DecimalEdm.Int64.这些值必须以OData的JSON格式序列化为字符串(即,以"字符包装的数字).如果不确定属性的声明类型是什么,可以在服务器的$metadata文档(通常在http://.../MyService.svc/$metadata中可用)中查找实体类型.

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).

因此,对于Edm.Int64Edm.Decimal的一个或多个属性,您可以删除对parseFloat()的调用,而只需将其保留为字符串即可.

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.

这篇关于WinJS OData JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆