This question already has answers here:
Parse Json string in C#
(5 answers)
Closed 6 years ago.
i have json string as following
string json = "{\"ID\":\"hid\",\"Specification\":\"hname\"}";
but i want to read Id and hname as following
string hid = hardwareidTextbox.Text;
string hname = hardwarename_Textbox.Text;
how do i read variable vales in JSON string
Try using
JsonConvert.DeserializeObject(json);
Related
This question already has answers here:
string.Replace (or other string modification) not working
(4 answers)
Closed 12 months ago.
I'm trying to replace a special character "½" with ".5"
cell.InnerText="o208½-105u208½-109o208-110u209-110";
string tempStr=cell.InnerText;
if (cell.InnerText.Contains("½"))
{
cell.InnerText.Replace("½", ".5");
}
string tempStr1 = cell.InnerText;
but my C# .Replace isn't working , I get the same result.
String is an immutable type. Compiler creates a new string after replacing. So try just this
var innerText = "o208½-105u208½-109o208-110u209-110";
innerText= innerText.Replace("½", ".5");
result
before - o208½-105u208½-109o208-110u209-110
after - o208.5-105u208.5-109o208-110u209-110
This question already has answers here:
Convert a list to a string in C#
(14 answers)
Closed 4 years ago.
I wanted to ask if it's possible to change List items to one string?
List<string> example = new List<string>();
example.Add("1");
example.Add("2");
example.Add("3");
string text = "123";
string.Join is for you
string s = string.Join("", example )
This question already has answers here:
Parse Json string in C#
(5 answers)
Closed 5 years ago.
How can i parse the following string to json object in C#:
string unescapedstring = " {"SettingName":"name","SettingValue":"\\log1\\log2\\","Description":"description"}"
to get:
{
"SettingName": "name",
"SettingValue": "\\log1\\log2\\",
"Description": "description"
}
Thanks.
You can use JObject class and its method .parse which accepts string as argument:
JObject jo = JObject.Parse(unescapedstring);
Newtonsoft_Json Library
This question already has answers here:
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 6 years ago.
I am attempting to replace characters in a string data type. Below is my code, but the ' is not being replaced with ''. Am I mis-understanding how the replace() function operates? What should I do in order to change the string to High Flying Picture''s?
This is the syntax I attempted.
public static void Test()
{
string strVar = "High Flying Picture's";
strVar.Replace("'", "''");
Console.WriteLine(strVar);
}
strVar = strVar.Replace("'", "''");
You need to reassign it.
This question already has answers here:
Regex To Extract An Object From A JSON String
(3 answers)
Closed 8 years ago.
string sample = "{\"STACK_SIZE\":4,\"thes_stack\":[4,4]}";
how can I parse it using RE in C#?
First of all this isn't a valid JSON, remove the backslashes.
Second, using a library like JSON.NET you can parse your sample.
string sample = "{"STACK_SIZE":4, "thes_stack":[4,4]}";
var parsed = JsonConvert.DeserializeObject<dynamic>(sample);
that will parse it into a dynamic type, if you want something more strongly typed create your own class:
class StackInfo
{
public int STACK_SIZE {get; set;}
public int[] thes_stack {get; set;}
}
then you can deserialize into it:
string sample = "{"STACK_SIZE":4, "thes_stack":[4,4]}";
var parsed = JsonConvert.DeserializeObject<StackInfo>(sample);
But since you didn't put exactly what you need or exactly what your problem is with the suggestions in the comments no one can really help you.