如何在c#string中存储json数据? [英] how to store json data in c# string?
问题描述
您好,
i想询问如何在C#字符串变量中存储来自API服务器的json数据。
这里是我从API生成的json字符串服务器。
{access_token:i7aJLVH_gySKIkNF1BI1zQ ==,scope:UtilityNetworkAuth,expires_in:57599,refresh_token: jMwIe1_33C1b2tFDahuvmA ==}
当我尝试这样做时将它存储在一个变量中并对其进行一些操作:
它显示为红色!
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 !
var json={"access_token":"i7aJLVH_SKIkNF1BI1zQ==","scope":"UtilityNetworkAuth","expires_in":57599,"refresh_token":"jMwIe1_33C1b2tFDahvmA=="}
i不知道怎么做因为所有互联网上的文章说我应该改变格式并把/或'(单引号)但我的问题在这里它每天都会生成,并且每次手动更改它都是不可能的! :D $ / $
i想知道如何在c变量中存储这样的json字符串#
我也尝试将其手动更改为单引号而不是双引号它工作但如何使它在双引号中工作如何将此json数据存储在变量c#
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#
推荐答案
参见。
http://stackoverflow.com/questions/25030498/parse-json-data-string-store-in-array [ ^ ]
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770289.aspx [ ^ ]
<小时ef =https://blog.udemy.com/c-sharp-json/> https://blog.udemy.com/c-sharp-json/ [ ^ ]
See .
http://stackoverflow.com/questions/25030498/parse-json-data-string-store-in-array[^]
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770289.aspx[^]
https://blog.udemy.com/c-sharp-json/[^]
你可以存储类似的东西一个字符串。
我认为问题在于定义一个常量字符串,你这样做:
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";
因为你的json中有双引号,你需要逃避它们:
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.
这篇关于如何在c#string中存储json数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!