To parse JSON data from text file using c# winforms -
To parse JSON data from text file using c# winforms -
i have numbers of text files containing json data, want parse required info files. creating c# windows app task. please help me same, thanx lot in advance
here text file info sample:
name: sample testname username: samplexyz time zone: sampletimezone language: en json: { "id": 600723423551234234234, "id_str": "600723423551234234234", "name": "sample testname", "screen_name": "samplexyz", "location": "sample location", "description": "sampledescritpin", "url": null, "entities": { "description": { "urls": [] } }, //some unwanted info in between }
first need extract json file; this:
static string extractjson(string path) { var file = file.readalltext(path); var brackets = 0; var json = ""; foreach (var c in file) { if (c == '{') // if { encountered, go in level brackets++; else if (c == '}') // if } encountered go out level { brackets--; if (brackets == 0) json += c.tostring(); // lastly bracket } if (brackets > 0) // ignore isn't within brackets json += c.tostring(); } homecoming json; }
then 1 time have json data, utilize parser 1 newtonsoft parse json
c# json winforms json.net
Comments
Post a Comment