Skip to content

Commit 63b6274

Browse files
committed
修复了天气预警无法使用的问题。
1 parent 76e5943 commit 63b6274

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

QWeatherAPI.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{5A663551-0
1414
docs\Nuget-README-1.1.0.md = docs\Nuget-README-1.1.0.md
1515
docs\Nuget-README-1.2.0.md = docs\Nuget-README-1.2.0.md
1616
docs\Nuget-README-1.3.0.md = docs\Nuget-README-1.3.0.md
17+
docs\Nuget-README-1.3.1.md = docs\Nuget-README-1.3.1.md
1718
README.md = README.md
1819
EndProjectSection
1920
EndProject

src/ExampleApp/ExampleConsoleApp/ExampleConsoleApp.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
16-
<PackageReference Include="QWeatherAPI" Version="1.2.0" />
15+
<ProjectReference Include="..\..\QWeatherAPI\QWeatherAPI.csproj" />
1716
</ItemGroup>
1817

1918
</Project>

src/ExampleApp/ExampleConsoleApp/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private static async Task GetWeatherAsync()
1818
var locationInfo = (await QWeatherAPI.GeoAPI.GetGeoAsync(location, key)).Locations[0];
1919
var realTimeWeatherInfo = await QWeatherAPI.RealTimeWeatherAPI.GetRealTimeWeatherAsync(locationInfo.Lon, locationInfo.Lat, key);
2020
var forecastWeatherInfo = await QWeatherAPI.WeatherDailyForecastAPI.GetWeatherDailyForecastAsync(locationInfo.Lon, locationInfo.Lat, key);
21+
var warningResult = await QWeatherAPI.WeatherWarningAPI.GetWeatherWarningAsync(locationInfo.Lon, locationInfo.Lat, key);
2122
Console.WriteLine(@$"{locationInfo.Name} 的天气
2223
当前温度 {realTimeWeatherInfo.Now.Temp}°C
2324
体感温度 {realTimeWeatherInfo.Now.FeelsLike}°C
@@ -29,6 +30,9 @@ private static async Task GetWeatherAsync()
2930
最低温 {forecastWeatherInfo.Daily[1].TempMin}
3031
{forecastWeatherInfo.Daily[1].TextDay}
3132
{forecastWeatherInfo.Daily[1].WindDirDay}
33+
34+
预警类型 {warningResult.Warning[0].TypeName}
35+
预警级别 {warningResult.Warning[0].Level}
3236
");
3337
}
3438
catch (ArgumentException ex)

src/QWeatherAPI/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
3333
//通过使用 "*",如下所示:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.3.1.0")]
36-
[assembly: AssemblyFileVersion("1.3.1.0")]
35+
[assembly: AssemblyVersion("1.3.2.0")]
36+
[assembly: AssemblyFileVersion("1.3.2.0")]

src/QWeatherAPI/Result/WeatherWarning/WarningResult.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ public struct WarningResult
2626
/// </summary>
2727
public Warning[] Warning;
2828

29-
public WarningResult(JToken token)
29+
public WarningResult(string jsonString)
3030
{
31-
Code = token.Value<string>("code");
32-
UpdateTime = token.Value<string>("updateTime");
33-
FxLink = token.Value<string>("fxLink");
31+
JObject jsonData = JObject.Parse(jsonString);
32+
Code = jsonData.Value<string>("code");
33+
UpdateTime = jsonData.Value<string>("updateTime");
34+
FxLink = jsonData.Value<string>("fxLink");
3435
List<Warning> warnings = new List<Warning>();
35-
foreach (var warning in token.SelectToken("warning"))
36+
foreach (var warning in jsonData.SelectToken("warning"))
3637
{
3738
warnings.Add(new Warning(warning));
3839
}

0 commit comments

Comments
 (0)