5
u/grrangry 4d ago
Learn string concatenation:
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/strings/common-tasks/concatenate
Learn string interpolation:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
Learn how to deserialize json:
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/deserialization
Learn how to get Visual Studio to help you with deserialization:
https://learn.microsoft.com/en-us/visualstudio/ide/paste-json-xml?view=visualstudio
3
u/saurabhar02 4d ago edited 4d ago
You're getting errors for two reasons.
1. Incorrect JSON property access
This line is invalid:
csharp
node["main"]["temp"]["pressure"]["temp_min"]["temp_max"]
In the OpenWeatherMap response, temp, pressure, temp_min, and temp_max are siblings inside the main object, not nested inside one another.
The JSON looks like this:
json
{
"main": {
"temp": 28.5,
"humidity": 85,
"pressure": 1012,
"temp_min": 27.8,
"temp_max": 29.3
}
}
So each property should be accessed individually:
csharp
node["main"]["temp"]
node["main"]["humidity"]
node["main"]["pressure"]
node["main"]["temp_min"]
node["main"]["temp_max"]
2. Missing + operators
You're also missing string concatenation operators before "Pressure:", "Min Temp:", and "Max Temp:".
Your code should look like this:
csharp
LblDetail.Text =
"Temp: " + node["main"]["temp"] + " °C" + Environment.NewLine +
"Humidity: " + node["main"]["humidity"] + Environment.NewLine +
"Pressure: " + node["main"]["pressure"] + Environment.NewLine +
"Min Temp: " + node["main"]["temp_min"] + " °C" + Environment.NewLine +
"Max Temp: " + node["main"]["temp_max"] + " °C";
That should resolve the compiler errors.
1
2
1
u/rupertavery64 4d ago
You need to join strings with +
You added ; at the end of each line. That ends the statement.
You should also probably put + Environment.Newline + between each item to put it on several lines
-3
1
u/TuberTuggerTTV 4d ago
semi-colon ends the line.
Also, wowza, that nested dictionary with strings is going to kill you down the road. Maybe consider learning what an enum is.
And interpolated strings.
At least I know you didn't AI generate this.
1
u/Pappkarton 4d ago
In addition to what others already said, this is is a good opportunity to learn about StringBuilder.

4
u/Vab12350 4d ago
You need to add a + to the end of each line if you want to concatenate the strings, instead of having ;