Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,
i would like to ask about how to store json DATA coming from an API server in a C# string variable.
here is my generated json string from API server .

{"access_token":"i7aJLVH_gySKIkNF1BI1zQ==","scope":"UtilityNetworkAuth","expires_in":57599,"refresh_token":"jMwIe1_33C1b2tFDahuvmA=="}

when i try to do like this to store it in a variable and do some operations on it :
it appear red !
C#
var json={"access_token":"i7aJLVH_SKIkNF1BI1zQ==","scope":"UtilityNetworkAuth","expires_in":57599,"refresh_token":"jMwIe1_33C1b2tFDahvmA=="}


i dont know what to do bec all the articles in the internet says that i should change the format and put / or ' (single quotes ) but my problem here that it generate everyday and it impossiblle to change it everytime manually ! :D


i want to know how can i store json string like this in a variable in c#

also i tried to change it manually to single quotes instead of double quotes it working but how to make it work in double quotes how to store this json data in a variable c#
Posted
Updated 20-May-18 23:26pm
v2

 
Share this answer
 
Comments
Hesham el Masry 12-Feb-15 8:02am    
no one of them will work with me because the json variable appear red line to me
You can store anything like that in a string.

What I think the problem is here is that to define a constant string you do it like this:
string x = "This is my string";

Because your json has double-quotes in them, you need to escape them:
var json="{\"access_token\":\"i7aJLVH_SKIkNF1BI1zQ==\",\"scope\":\"UtilityNetworkAuth\",\"expires_in\":57599,\"refresh_token\":\"jMwIe1_33C1b2tFDahvmA==\"}";


This can be painful for constants, so I usually just stick the string in a resource file.
 
Share this answer
 
Comments
Hesham el Masry 23-Feb-15 0:38am    
thank you it really hepled me :)
Member 13359885 21-May-18 6:59am    
https://www.codeproject.com/Questions/1242329/Datagrid-view-find-value-without-textbox-dirceted


Please Solve My Question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900