Zdravím,
už delší dobu se snažím rozchodit parsování json kodu na widows 8 metro a nevím si rady jak na to už při samostatném čtení. Pokud někdo pomůže budu mu moc vděčný a velmi děkuji.
Padá to na řádku: var response = await httpClient.GetAsync("api/json.php");
Obsah json.php
[{"ID":1,"Username":"TEST","UserTest":"TEST1"},{"ID":2,"Username":"TEST2","UserTest":"TEST3"}]
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Net.Http.Headers;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?…
namespace App5
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private HttpClient httpClient;
public MainPage()
{
this.InitializeComponent();
httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://192.168.1.39/api/json.php");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.MaxResponseContentBufferSize = 256000;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private async void GetUser(object sender, RoutedEventArgs e)
{
btnGetUsers.IsEnabled = false;
var response = await httpClient.GetAsync("api/json.php");
response.EnsureSuccessStatusCode(); // Throw on error code.
var users = await response.Content.ReadAsStringAsync();
OutputView.Text = users;
}
}
}