File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
samples/QuickstartWeatherServer/Tools Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,11 @@ public static async Task<string> GetForecast(
42
42
[ Description ( "Longitude of the location." ) ] double longitude )
43
43
{
44
44
using var jsonDocument = await client . ReadJsonDocumentAsync ( $ "/points/{ latitude } ,{ longitude } ") ;
45
- var jsonElement = jsonDocument . RootElement ;
46
- var periods = jsonElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
45
+ var forecastUrl = jsonDocument . RootElement . GetProperty ( "properties" ) . GetProperty ( "forecast" ) . GetString ( )
46
+ ?? throw new Exception ( $ "No forecast URL provided by { client . BaseAddress } points/{ latitude } ,{ longitude } ") ;
47
+
48
+ using var forecastDocument = await client . ReadJsonDocumentAsync ( forecastUrl ) ;
49
+ var periods = forecastDocument . RootElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
47
50
48
51
return string . Join ( "\n ---\n " , periods . Select ( period => $ """
49
52
{ period . GetProperty ( "name" ) . GetString ( ) }
@@ -52,4 +55,4 @@ public static async Task<string> GetForecast(
52
55
Forecast: { period . GetProperty ( "detailedForecast" ) . GetString ( ) }
53
56
""" ) ) ;
54
57
}
55
- }
58
+ }
You can’t perform that action at this time.
0 commit comments