首页 > 解决方案 > 如何实现通过 C# 发送 Expo.io 推送通知

问题描述

我想在以下代码中实现expo.io推送通知,抛出错误说:C#

当前上下文中不存在 JsonExtension

.

{
    public static dynamic SendPushNotification(string ExpoToken)
    {
        dynamic body = new
        {
            to = ExpoToken,
            title = "hello",
            body = "world",
            sound = "default",
            data = new { some = "daaaata" }
        };
        string response = null;
        using (WebClient client = new WebClient())
        {
            client.Headers.Add("accept", "application/json");
            client.Headers.Add("accept-encoding", "gzip, deflate");
            client.Headers.Add("Content-Type", "application/json");
            response = client.UploadString("https://exp.host/--/api/v2/push/send", JsonExtensions.ToJson(body));
        }
        var json = JsonExtensions.FromJson<dynamic>(response);
        return json;
    }
}```




标签: c#expowebclient

解决方案


看起来您的代码正在尝试使用Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions.FromJson方法,该方法对您不可用并且是Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll的一部分

我建议您改用此方法:

JsonConvert.DeserializeObject

在 Json.NET 中可用

还假设您正在尝试运行此 gist中的代码,我建议您查看此fork


推荐阅读