如何从Android的SignalR调用中获取数据

huangapple go评论97阅读模式
英文:

how to get data from android signalr invoke

问题

如何从调用方法中检索数组?调用方法可正常运行,但我找不到如何在Java客户端中从中获取数组。

   HubConnection hubConnection;
        hubConnection = HubConnectionBuilder.create(Constants.BASE_LOCAL_HUB_URL).withAccessTokenProvider(Single.defer(() -> {
            // Your logic here.
            return Single.just(token);
        })).build();
        hubConnection.invoke(UserViewModel[].class, "GetUsers");
英文:

How can can retrieve the array from invoke method? The invoke method works, but I couldn't find how I can get the array from it in Java client.

   HubConnection hubConnection;
        hubConnection = HubConnectionBuilder.create(Constants.BASE_LOCAL_HUB_URL).withAccessTokenProvider(Single.defer(() -> {
            // Your logic here.
            return Single.just(token);
        })).build();
        hubConnection.invoke(UserViewModel[].class, "GetUsers");

答案1

得分: 1

Invoke方法返回一个Single<T>,其中T是您指定的类型(UserViewModel[])。

因此,您需要通过订阅该Single来使用返回值。https://www.tutorialspoint.com/rxjava/rxjava_single_observable.htm

测试其是否正常工作的最快方法是执行:

UserViewModel[] arr = hubConnection.invoke(UserViewModel[].class, "GetUsers").blockingGet();
英文:

Invoke returns a Single&lt;T&gt; where T is the type you specified (UserViewModel[]).

So you need to use the return value by subscribing to the Single. https://www.tutorialspoint.com/rxjava/rxjava_single_observable.htm

The quickest way to test it is working is to do:

UserViewModel[] arr = hubConnection.invoke(UserViewModel[].class, &quot;GetUsers&quot;).blockingGet();

huangapple
  • 本文由 发表于 2020年7月27日 20:17:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63115164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定