Converting a Python app to Console app (C# JSON)

Hi CSharp,

I'm attempting to convert a Python application over to C#. I'm still very new to C# and it's concepts (I can create classes, understand variables and inport external libs.).

The Problem

I'm attempting to convert a Python script. The script does the following.

1) Sets up a GET request, grabs the data and returns a json dict.

an example in Python

the url is known as the payload or URI in C#.

url = ',' 'national-rail,cable-car,river-bus,river-tour/status'

a = requests.get(url) 

The requests.get module simply grabs the json data as is.

serialize the json into a secondry object.

 dataq = b.json() 

work with the json

for i in dataq: print("{}".format(i['name'])) for status in i['lineStatuses']: print(" {}".format(status['statusSeverityDescription'])) if status['statusSeverity'] != 10: print(" {}".format(status['reason'])) print('\n') 

2) The json dict can then be iterated thru without any problems (see above)

I've attempted to try and research methods of recreating this exact mechanism online. alot of the sites recommend the In-order to work with JSON in C# you need to deserizlise the payload, I'm struggling however to extract the data from the strings (in python these would be dicts or tuples.) I was able to grab some data using the Async download to string method however the data is still stuck in memory. If i attempt to create and enfuse a dict from a string I also get errors.

I was wondering if someone could provide an example of a multilayer json node traversal with async/http download/remote get. I've noticed theres a json2csharp generator. The URI is

It's toplogy is rather complex. I have been able to make a python app using the requests module and json() (an inbuilt json seralizer with requests.) however attempting the same on C# is harder thanks to the fact of having to use classes plus declaring each item as well as getting a new grip on the c# syntax.

If anyone could assist with helping me understand the way to grab, get and manuipluate json data from remote sources and provide examples I would be very greatful.

Thanks again Oliver

by Oli_Picard via /r/csharp

Leave a Reply