[英]How to pass object from JavaScript to Windows Runtime Component C#?
I do have the following object param in JavaScript and I want to pass it to C# Windows Runtime Component for Windows Apps. 我在JavaScript中确实具有以下对象参数 ,并且我想将其传递给Windows Apps的C#Windows运行时组件。
var param = {
"url" : "http://192.168.101.224/DEMO/All/DemoService.svc/login",
"requesttype" : "POST",
"paramss" : {
"userName" : "demouser",
"password" : "abcdef",
"domain" : "demodomain",
"accessKey" : "12345"
}
}
.....
callWebservice: function (param, callBack) {
try {
service = new ServcieRuntimes.Service();
service.callHttpService(param).then(function (data) { ... )};
In the C#, WinRT Component class, I'm doing like this. 在C#,WinRT Component类中,我这样做。
public IAsyncOperation<string> CallHttpService(string param)
{
return CallHttpServiceHelper(json).AsAsyncOperation();
}
private async Task<string> CallHttpServiceHelper(string param)
{
try
{ ....... }
But I'm getting 但是我越来越
[object Object]
in C#. 在C#中。
Please help me on this. 请帮我。 Thanks in advance! 提前致谢!
Your C# code expects a (presumably JSON) string, you need to supply one 您的C#代码需要一个(大概是JSON)字符串,您需要提供一个
service.callHttpService(JSON.stringify(param)).then(function (data) { ... )};
You currently get 您目前得到
[object Object]
because that's the output of {}.toString(); 因为那是{} .toString();的输出;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.