Shreyas Rao B
Shreyas Rao B

Reputation: 193

How to convert JsonString to String?

JsonString.txt

{ "profile": { "name": { "formatted": "John Jackson", "givenName": "John", "familyName": "Jackson" }, "verifiedEmail": "[email protected]", "googleUserId": "1048morenumbers2048", "displayName": "John Jackson", "photo": " " , "preferredUsername": "rpxstaging", "url": " ", "providerName": "Google","identifier": " ", "birthday":"1994-05-19", "gender":"female", "email": "[email protected]" }, "accessCredentials":{ "oauthToken":"1/V2UImanylettersandnumbersrnWlVS7c", "oauthTokenSecret":"i5rlettersQU-32moreVY", "scopes": "Blogger,Google Contacts,YouTube,Picasa Web,Albums,Google Calendar,Google Docs,Google Mail,Google OpenSocial" , "scope":" ", "type":"OAuth" }, "merged_poco": { "name": { "formatted": "John Jackson", "givenName": "John", "familyName": "Jackson" }, "addresses": [ { "country": "United States" } ], "photos": [ { "type": "other", "value": " " } ], "urls": [ { "type": "profile", "value": " " } ], "preferredUsername": "rpxstaging", "emails": [ { "type": "other", "value": "[email protected]" } ], "languagesSpoken": [ "en-US" ], "id":"1048numbers2048", "displayName": "John Jackson", "profileUrl": " " }, "stat": "ok" }

String.txt

{ \"profile\": { \"name\": { \"formatted\": \"John Jackson\", \"givenName\": \"John\", \"familyName\": \"Jackson\" }, \"verifiedEmail\": \"[email protected]\", \"googleUserId\": \"1048morenumbers2048\", \"displayName\": \"John Jackson\", \"photo\": \" \" , \"preferredUsername\": \"rpxstaging\", \"url\": \" \", \"providerName\": \"Google\", \"identifier\": \" \", \"birthday\":\"1994-05-19\", \"gender\":\"female\", \"email\": \"[email protected]\" }, \"accessCredentials\":{ \"oauthToken\":\"1/V2UImanylettersandnumbersrnWlVS7c\", \"oauthTokenSecret\": \"i5rlettersQU-32moreVY\", \"scopes\": \"Blogger,Google Contacts,YouTube,Picasa Web Albums,Google Calendar,Google Docs,Google Mail,Google OpenSocial\" , \"scope\": \"\", \"type\": \"OAuth\" }, \"merged_poco\": { \"name\": { \"formatted\": \"John Jackson\", \"givenName\": \"John\", \"familyName\": \"Jackson\" }, \"addresses\": [ { \"country\": \"United States\" } ], \"photos\": [ { \"type\": \"other\", \"value\": \" " } ], \"urls\": [ { \"type\": \"profile\", \"value\": \" \" } ], \"preferredUsername\": \"rpxstaging\", \"emails\": [ { \"type\": \"other\", \"value\": \"[email protected]\" } ], \"languagesSpoken\": [ \"en-US\" ], \"id\": \"1048numbers2048\", \"displayName\": \"John Jackson\", \"profileUrl\": \" \" }, \"stat\": \"ok\" }

Upvotes: 1

Views: 664

Answers (1)

Habib
Habib

Reputation: 223267

If you have the above json in a text file then you can simply do:

string strJson = File.ReadAllText("jsonstring.txt"); //Specify the path

The required value (second json) is just the way debugger shows it. You probably don't need escaped values as in actual string.

In debugger it would appear as:

enter image description here

Upvotes: 2

Related Questions