0

I need to store value like

string stringValue = {"E":false,"T":1,"I":[],"M":"","S":false,"ST":1};

in string.

I have a value given as above and i want to store this value in a single string. Please somebody help me.

vahid kargar
  • 800
  • 1
  • 9
  • 23
Manish Jain
  • 1,197
  • 1
  • 11
  • 32

2 Answers2

2

You can escape double quote by back slash, you can find more about escaping string here

string stringValue = "{\"E\":false,\"T\":1,\"I\":[],\"M\":\"\",\"S\":false,\"ST\":1}";

A character that follows a backslash character () in a regular-string-literal-character must be one of the following characters: ', ", \, 0, a, b, f, n, r, t, u, U, x, v. Otherwise, a compile-time error occurs, MSDN.

Adil
  • 146,340
  • 25
  • 209
  • 204
1

What you are trying to store is actually JSON

You can easily store it into a string by serializing it first:

For this you can use the JavaScriptSerializer class that is part of System.Web.Script.Serialization

using System.Web.Script.Serialization;

...

string stringValue = JavaScriptSerializer().Serialize(YourJsonObject);
//YourJsonObject here would be the object you are getting the value from.

You can then later reverse the process by deserializing it back to an object:

var myJsonObj = JavaScriptSerializer().Deserialize(stringValue);

Note: The class is part of the System.Web.Extensions assembly.

JanR
  • 6,052
  • 3
  • 23
  • 30