简体   繁体   English

从JavaScript调用函数时返回C#对象

[英]Returning a C# object when function is called from JavaScript

I'm working on a WinJS Windows app and need to write some C# to multithread some of the data parsing because it slows the app significantly. 我正在使用WinJS Windows应用程序,需要编写一些C#来对某些数据解析进行多线程处理,因为这会大大降低应用程序的速度。 I am hoping to write a C# function which will make a web service call, parse the data in order to keep track of a whole bunch of properties (some ints, arrays or lists, strings, etc), and then return all of those properties to be used by the JavaScript. 我希望编写一个C#函数,该函数将进行Web服务调用,解析数据以便跟踪一堆属性(某些int,数组或列表,字符串等),然后返回所有这些属性由JavaScript使用。

Is there a way to return a C# Object or dictionary and have it be usable as a JavaScript object? 有没有办法返回C#对象或字典并将其用作JavaScript对象?

Yes you can, you can create your own Windows Runtime Component in C# and call it from your javascript code. 是的,您可以,您可以使用C#创建自己的Windows运行时组件 ,然后从JavaScript代码中调用它。

Having said that I don't think you need it for your scenario. 话虽如此,我认为您不需要这种情况。 You can call your service with an instance of the HttpClient client class. 您可以使用HttpClient客户端类的实例来调用服务。 If the service returns json data you can just call JSON.parse in order to get an object that represents the returned data. 如果服务返回json数据,则可以仅调用JSON.parse以获得代表返回数据的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM