I have problems when displaying data by taking data from JSON (arrays in the array). That is when the gridview selected, then immediately exit the application and will display an error message, as below:
Code:
private BukuAudio itemDetail = null;
public async void StoreAll()
{
try
{
var client = new Windows.Web.Http.HttpClient();
string urlPath = "website";
var values = new List<KeyValuePair<string, string>>
{
};
var response = await client.PostAsync(new Uri(urlPath), new Windows.Web.Http.HttpFormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
string jsonText = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(jsonText);
JsonArray jsonData1 = jsonObject["data"].GetArray();
foreach (JsonValue groupValue in jsonData1)
{
JsonObject groupObject = groupValue.GetObject();
string nid = groupObject["sku"].GetString();
string title = groupObject["judul"].GetString();
string deskripsi = groupObject["deskripsi"].GetString();
string tipe = groupObject["tipe"].GetString();
var bundleObj = groupObject["bundle"];
if (bundleObj.ValueType == JsonValueType.Array)
{
JsonArray bundle = bundleObj.GetArray();
foreach (JsonValue groupValue1 in bundle)
{
JsonObject groupObject1 = groupValue1.GetObject();
string bundleName = groupObject1["bundle_file"].GetString();
string pathFile = groupObject1["path_file"].GetString();
BukuAudio file1 = new BukuAudio();
file1.BundleName = bundleName;
file1.Tipe = tipe1;
if (file1.Tipe == "0")
{
file1.BundlePath = pathFile + bundleName + ".pdf";
}
else if (file1.Tipe == "1")
{
file1.BundlePath = pathFile + bundleName + ".mp3";
}
}
}
BukuAudio file = new BukuAudio();
file.SKU = nid;
file.Judul = title;
file.Deskripsi = deskripsi;
file.Tipe = tipe;
if (bundleObj.ValueType == JsonValueType.Array)
{
datasource.Add(file);
}
}
if (jsonData1.Count > 0)
{
itemGridView.ItemsSource = datasource;
}
}
catch
{
}
private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
ProductDetail.IsOpen = true;
itemDetail = e.ClickedItem as BukuAudio;
DetailSKU.Text = itemDetail.SKU;
DetailJudul.Text = itemDetail.Judul;
DetailDeskripsi.Text = itemDetail.Deskripsi;
DetailBundleName.Text = itemDetail.BundleName;
DetailTipe.Text = itemDetail.Tipe;
}
I've debug file1.bundleName and data is not empty, but if it is put on the data becomes null itemDetail.BundleName
How to handle it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…