简体   繁体   English

asp.net-> javascript-> webservice->从webservice调用返回两个类

[英]asp.net -> javascript -> webservice -> Returning two classes from webservice call

Ok, I have a webservice that I created. 好的,我有一个创建的Web服务。 Initially, I created a class, populated that class, and then returned that class to my javascript. 最初,我创建了一个类,并填充了该类,然后将该类返回给我的JavaScript。

psuedocode 伪码

Return myClass.toarray

....Turns out I need to pass even more data back during this call. ....事实证明,我需要在通话过程中传回更多数据。 In turn I will have two classes that I need to pass back to my javascript. 反过来,我将需要两个类传递回我的JavaScript。 I tried putting them into an array and that wasn't working I also tried some other things that didn't really make a lot of sense. 我尝试将它们放入数组中,但没有用,我还尝试了其他一些没有太大意义的事情。 Any advice on this would be greatly appreciated, I am sure others have run into this type of situation previously. 任何对此的建议将不胜感激,我相信其他人以前也曾遇到过这种情况。 I know that you have to put them into an object but haven't figured out how to do this as of yet. 我知道您必须将它们放入一个对象中,但到目前为止还没有弄清楚如何执行此操作。

Basically, my question is, how do you pass two class objects back to javascript? 基本上,我的问题是,如何将两个类对象传递回javascript?

I think something along these lines may solve your problem 我认为遵循这些思路可以解决您的问题

But even in this example the second class is like an inner class but you can get it easily on deserialization 但是即使在此示例中,第二个类也像一个内部类,但是您可以在反序列化时轻松获得它

http://blogs.msdn.com/b/rakkimk/archive/2009/01/30/asp-net-json-serialization-and-deserialization.aspx http://blogs.msdn.com/b/rakkimk/archive/2009/01/30/asp-net-json-serialization-and-deserialization.aspx

I experienced this before. 我以前经历过。 I decided not to return to class. 我决定不回到课堂。 Instead, I just try to combine both of my class into a single class. 相反,我只是尝试将我的两个班级合并为一个班级。 And then return the merged array. 然后返回合并的数组。 But this will depend on how you will use that array. 但这取决于您将如何使用该数组。 If you want to separate them back. 如果您想将它们分开。 You may want to put special character as marker between the two stacks. 您可能需要在两个堆栈之间放置特殊字符作为标记。

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

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