我在创建通用应用程序方面比较新
我在 .txt 文件中有 JSON。 xaml 中的图像和文本框
我需要从 .txt 读取 JSON 并将文本从 JSON 解析为 TextBox。 对于图像,我需要通过 JSON 格式的 url 下载它
我的JSON
Array
(
[0] => Array
(
[post_title] => Ролл Чеддер c темпура креветкой
[post_excerpt] => Рис, нори, темпура креветка, сыр филадельфия, огурец, сыр чеддер, соус голландский
[img_url] => http://new.murakami.ua/wp-content/uploads/535_520Rol-chedr-s-sirom-filadelfiej-i-tempura-krevetkoyu.jpg
[visibility] => visible
[price] => 124.00
[weight] => 195/16
[sku] => 233
)
[1] => Array
(
[post_title] => Ролл спайси лосось
[post_excerpt] => Рис, нори, лосось, спайси соус, икра масаго, зеленый лук
[img_url] => http://new.murakami.ua/wp-content/uploads/535_520Rol-spajsi-losos.jpg
[visibility] => visible
[price] => 68.00
[weight] => 130/16
[sku] => 239
)
[2] => Array
(
[post_title] => Ролл с пастрами
[post_excerpt] => Рис, нори, пастрами, листья салата, перец болгарский, огурец, соус горчичный, помидор, голландский соус
[img_url] => http://new.murakami.ua/wp-content/uploads/535_520Rol-z-pastrami.jpg
[visibility] => visible
[price] => 98.00
[weight] => 185/16
[sku] => 245
)
[3] => Array
(
[post_title] => Ролл огуречный лосось
[post_excerpt] => Рис, нори, лосось, сыр филадельфия, сладкий омлет, икра тобико, огурец, голландский соус
[img_url] => http://new.murakami.ua/wp-content/uploads/535_520Rol-ogirkovij-losos.jpg
[visibility] => visible
[price] => 112.00
[weight] => 190/16
[sku] => 244
)
[4] => Array
(
[post_title] => Ролл оши абури с лососем и голландским соусом
[post_excerpt] => Рис, лосось, огурец, перец чили, голландский соус
[img_url] => http://new.murakami.ua/wp-content/uploads/535_520Oshi-aburi-z-lososem-i-golandskim-sousom.jpg
[visibility] => visible
[price] => 98.00
[weight] => 18016
[sku] => 240
)
我如何通过 Xamarin 在 Adroid 中做到这一点
var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var filename = System.IO.Path.Combine(path, "cache3.txt");
JsonValue readJson;
var jsonString = File.ReadAllText(filename);
readJson = JsonObject.Parse(jsonString);
private async void ParseAndDisplay1(JsonValue readJson)
{
TextView productname = FindViewById<TextView>(Resource.Id.posttittle);
TextView price = FindViewById<TextView>(Resource.Id.price);
TextView weight = FindViewById<TextView>(Resource.Id.weight);
ImageView imagen = FindViewById<ImageView>(Resource.Id.image1);
ImageButton add = FindViewById<ImageButton>(Resource.Id.add);
add.Click += delegate
{
var intent = new Intent(this, typeof(BludoDetail));
StartActivity(intent);
};
productname.Click += delegate
{
var intent485 = new Intent(this, typeof(BludoDetail));
StartActivity(intent485);
};
JsonValue firstitem = readJson[0];
productname.Text = firstitem["post_title"];
price.Text = firstitem["price"] + " грн";
weight.Text = firstitem["weight"];//"г";
Koush.UrlImageViewHelper.SetUrlDrawable(imagen, firstitem["img_url"], null, 5000000);
}
在 Xamarin.Android 中我有 Koush 插件,用于下载和缓存图像
如何在 UWP 中将信息从 Json 解析为 TextBox 以及如何下载图像并缓存它?
最佳答案
你可以使用 Json.NET解析 json。
您应该创建一个处理 json 并使用绑定(bind)的类,以便将数据与 xaml 组合。要下载图像,请使用 HttpClient
关于c# - 从文件 UWP (C#) 中读取 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37133832/