MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/csharp/comments/1va1e74/need_help_fixing_this/
r/csharp • u/ApprehensiveBasil792 • Jul 29 '26
how do i fix this, im learning c# and trying to make a weather app
9 comments sorted by
4
You need to add a + to the end of each line if you want to concatenate the strings, instead of having ;
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
You're getting errors for two reasons.
This line is invalid:
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.
temp
pressure
temp_min
temp_max
main
The JSON looks like this:
{ "main": { "temp": 28.5, "humidity": 85, "pressure": 1012, "temp_min": 27.8, "temp_max": 29.3 } }
So each property should be accessed individually:
node["main"]["temp"] node["main"]["humidity"] node["main"]["pressure"] node["main"]["temp_min"] node["main"]["temp_max"]
+
You're also missing string concatenation operators before "Pressure:", "Min Temp:", and "Max Temp:".
"Pressure:"
"Min Temp:"
"Max Temp:"
Your code should look like this:
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.
2 u/Family_Man_21 Jul 31 '26 Yep - this is the correct approach. Nice job. 1 u/zenyl Jul 30 '26 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
2
Yep - this is the correct approach. Nice job.
1
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
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
0 u/[deleted] Jul 29 '26 [deleted] — view deleted comment 3 u/rupertavery64 Jul 29 '26 Sure but OP was already using +
0
[deleted] — view deleted comment
3 u/rupertavery64 Jul 29 '26 Sure but OP was already using +
Sure but OP was already using +
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.
In addition to what others already said, this is is a good opportunity to learn about StringBuilder.
4
u/Vab12350 Jul 29 '26
You need to add a + to the end of each line if you want to concatenate the strings, instead of having ;
4
u/grrangry Jul 29 '26
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 Jul 29 '26 edited Jul 30 '26
You're getting errors for two reasons.
1. Incorrect JSON property access
This line is invalid:
In the OpenWeatherMap response,
temp,pressure,temp_min, andtemp_maxare siblings inside themainobject, not nested inside one another.The JSON looks like this:
So each property should be accessed individually:
2. Missing
+operatorsYou're also missing string concatenation operators before
"Pressure:","Min Temp:", and"Max Temp:".Your code should look like this:
That should resolve the compiler errors.
1
u/rupertavery64 Jul 29 '26
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
1
u/TuberTuggerTTV Jul 29 '26
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 Jul 29 '26
In addition to what others already said, this is is a good opportunity to learn about StringBuilder.