【问题标题】:Zxing and Xamarin formsZxing 和 Xamarin 形式
【发布时间】:2020-07-05 14:54:45
【问题描述】:

我正在制作一个 xamarin 形式的应用程序,它必须使 wark 的所有东西都非常好,现在我正试图让它变得更好一点。

该应用程序现在创建一个文章列表视图(仅代码和描述),从我服务器上的 API 获取它们,当我点击列表视图的项目时,它会显示更多信息和该文章的价格。 我已经安装了 Zxing 包来直接读取 ean_code 并跳过列表视图。 来自服务器的 API 工作(尝试使用 Postman),但在应用程序上它给我一个错误“值不能为空。参数名称:stringToEscape”

这是我为搜索插入过滤器或单击以阅读 Ean_code 的页面代码:

    public void TapArticolo(object sender, ItemTappedEventArgs e)
    {
        Articolo Articolo_selezionato = (Articolo) ((ListView)sender).SelectedItem; //Link the tapped Item to the class variabile
        Navigation.PushModalAsync(new SchedaArticoloPage(Articolo_selezionato)); // Call the new page passing the class like parameter (Only Cod_articolo and Descr_1)
    }

    private void Button_Ean_Clicked(object sender, EventArgs e)
    {
        var scan = new ZXingScannerPage();
        Navigation.PushModalAsync(scan);
        scan.OnScanResult += (result) =>
        {
            Device.BeginInvokeOnMainThread(async () =>
                {
                    await Navigation.PopModalAsync();
                    Articolo Articolo_selezionato = new Articolo(); // Initialize the Class 
                    Articolo_selezionato.Ean_code = result.ToString(); // Write the Ean code inside the class
                    await Navigation.PushModalAsync(new SchedaArticoloPage(Articolo_selezionato));  // Call the new page passing the class like parameter (Only Ean_Code)
                });
        };
     
    }

这是收集后必须显示详细数据的页面:

public partial class SchedaArticoloPage : ContentPage
{
    public SchedaArticoloPage(Articolo Articolo_selezionato)
    {
        var SchedaArticoloViewModel = new SchedaArticoloViewModel();    //Initialize the ViewModel
        SchedaArticoloViewModel.Articolo_selezionato = Articolo_selezionato;  //Link the given Parameter to the class of the viewModel
        if (Articolo_selezionato.Cod_articolo != null) SchedaArticoloViewModel.Dati_articolo.Execute(null);  // Execute in case of tap (only the Cod_articolo is present)
        if (Articolo_selezionato.Ean_code != null) SchedaArticoloViewModel.Dati_articolo_da_ean.Execute(null);  //Execute in case of Ean code Read (only Ean code present)
        SchedaArticoloViewModel.Listini_Articolo_command.Execute(null); // Retrive price whan all the record of the class are present
        BindingContext = SchedaArticoloViewModel;   //Bind the content
        InitializeComponent();
    }
}

结束这些是从服务器收集数据的api:

    public async Task<Articolo> GetAnagraficaArticolo(string AccessToken, string cod_articolo)
    {
        server = Settings.Server;
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
        var json = await client.GetStringAsync(server + "/api/Articolo?cod_articolo=" + Uri.EscapeUriString(cod_articolo));
        var Articolo = JsonConvert.DeserializeObject<Articolo>(json);
        return Articolo;
    }

    public async Task<Articolo> GetAnagraficaArticoloDaEan(string AccessToken, string Ean_Code)
    {
        server = Settings.Server;
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
        var json = await client.GetStringAsync(server + "/api/Articolo?Ean_code=" + Uri.EscapeUriString(Ean_Code));
        var Articolo = JsonConvert.DeserializeObject<Articolo>(json);
        return Articolo;
    }

使用普通代码它就像一个魅力,使用 ean_code 它崩溃。真不知道哪里错了。

提前感谢您的帮助

【问题讨论】:

  • 哪一行导致了异常?
  • @Jason var json = await client.GetStringAsync(server + "/api/Articolo?Ean_code=" + Uri.EscapeUriString(Ean_Code));
  • 或者至少看起来是那一行
  • 错误“值不能为空。参数名称:stringToEscape”会让我认为您将空值传递给Uri.EscapeUriString(Ean_Code)
  • @Jason 检查,访问令牌和 Ean_code 存在。但我认为,如果程序在那里中断,问题也不存在,当然我也尝试复制有效的部分(上面带有 cod_articolo 的部分)给出修复参数来检查程序的其余部分,并且程序中断相同。此外,如果代码是正确的(上面的工作)

标签: rest xamarin.forms zxing


【解决方案1】:

不知道为什么,但是换了手机连接,它已经开始正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 2021-03-03
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多