How to Deserialize JSON data?

You can deserialize this really easily. The data’s structure in C# is just List<string[]> so you could just do; List<string[]> data = JsonConvert.DeserializeObject<List<string[]>>(jsonString); The above code is assuming you’re using json.NET. EDIT: Note the json is technically an array of string arrays. I prefer to use List<string[]> for my own declaration because it’s imo more … Read more

How to post data using HttpClient?

You need to use: await client.PostAsync(uri, content); Something like that: var comment = “hello world”; var questionId = 1; var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>(“comment”, comment), new KeyValuePair<string, string>(“questionId”, questionId) }); var myHttpClient = new HttpClient(); var response = await myHttpClient.PostAsync(uri.ToString(), formContent); And if you need to get the response after post, … Read more

Why do I get an OutOfMemoryException when I have images in my ListBox?

Oh, I recently killed whole day to make this working! So the solution is: Make your Image control free resources. So set the BitmapImage bitmapImage = image.Source as BitmapImage; bitmapImage.UriSource = null; image.Source = null; as it was mentioned before. Make sure you virtualize _bitmap on every item of the list. You should load it … Read more

Call asynchronous method in constructor?

The best solution is to acknowledge the asynchronous nature of the download and design for it. In other words, decide what your application should look like while the data is downloading. Have the page constructor set up that view, and start the download. When the download completes update the page to display the data. I … Read more

How to upload file to server with HTTP POST multipart/form-data?

Basic implementation using MultipartFormDataContent :- HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(new StringContent(username), “username”); form.Add(new StringContent(useremail), “email”); form.Add(new StringContent(password), “password”); form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), “profile_pic”, “hello1.jpg”); HttpResponseMessage response = await httpClient.PostAsync(“PostUrl”, form); response.EnsureSuccessStatusCode(); httpClient.Dispose(); string sd = response.Content.ReadAsStringAsync().Result;