3 changed files with 66 additions and 0 deletions
@ -0,0 +1,42 @@ |
|||||
|
using Newtonsoft.Json; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
using w230415_classes; |
||||
|
|
||||
|
namespace w230415_consoleapi |
||||
|
{ |
||||
|
internal class Program |
||||
|
{ |
||||
|
static void Main(string[] args) |
||||
|
{ |
||||
|
h_Process(); |
||||
|
} |
||||
|
|
||||
|
private static void h_Process() |
||||
|
{ |
||||
|
HttpClient client = new HttpClient(); |
||||
|
var res = client.GetAsync("http://localhost:5095/v1/hall").Result; |
||||
|
if (res.StatusCode == System.Net.HttpStatusCode.OK) |
||||
|
{ |
||||
|
string sJson = res.Content.ReadAsStringAsync().Result; |
||||
|
//// 1. self
|
||||
|
List<HallPlace>? chList = JsonConvert.DeserializeObject<List<HallPlace>>(sJson); |
||||
|
foreach (HallPlace item in chList) |
||||
|
{ |
||||
|
Console.WriteLine($"{item.SeatRow}/{item.SeatPosition}: {item.Uid}"); |
||||
|
} |
||||
|
// 2. dynamic
|
||||
|
//dynamic json = JsonConvert.DeserializeObject(sJson);
|
||||
|
//foreach (dynamic item in json)
|
||||
|
//{
|
||||
|
// Console.WriteLine($"{item.seatRow}/{item.seatPosition}: {item.uid}");
|
||||
|
//}
|
||||
|
// 3. JToken
|
||||
|
//JToken json = JsonConvert.DeserializeObject<JToken>(sJson);
|
||||
|
//foreach (JToken item in json)
|
||||
|
//{
|
||||
|
// Console.WriteLine($"{item["seatRow"]}/{item["seatPosition"]}: {item["uid"]}");
|
||||
|
//}
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<OutputType>Exe</OutputType> |
||||
|
<TargetFramework>net6.0</TargetFramework> |
||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||
|
<Nullable>enable</Nullable> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\w230415\w230415_classes.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
Loading…
Reference in new issue