13

I have a huge amount of customized attributes I want to save them in the DataBase, I was confused of how to store them in the database, i thought of storing them as a string separating them by

(= => name , value) (; => attribute , attribute) but the code wasn't elegant at all!

so i stat thinking of saving them as Json string but I couldn't found a Json to object parser

while we need only to call json() to parse object to json string

is there a better way than using json string and is there json string parser provided ?

dove
20.8k14 gold badges87 silver badges109 bronze badges
asked Nov 21, 2012 at 8:24
2
  • 1
    Why don't you save them just one by one in an key/value table? Commented Nov 21, 2012 at 8:29
  • 1
    they are alot .. this approach is so ugly ... thanks sir! Commented Nov 21, 2012 at 8:33

3 Answers 3

24

Try to use System.Web.Script.Serialization.JavaScriptSerializer, here is example:

var yourObject = new JavaScriptSerializer().Deserialize<YourType>(strInput)

or

var yourObject = new JavaScriptSerializer().Deserialize(strInput)
answered Nov 21, 2012 at 8:39
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome, no need of Json.net
Thanks, +1. FYI, this class is found in the System.Web.Extensions dll.
In, var yourObject = new JavaScriptSerializer().Deserialize(strInput), Deserialize takes on more input parameter of type.. it does not work directly by specifying the string. !!
18

Many people use Json.net for serialization

var log = JsonConvert.DeserializeObject<YourObject>(logJson)

and the other direction

 var logJson = JsonConvert.SerializeObject(log);
answered Nov 21, 2012 at 8:29

Comments

3

You can use $.parseJSON, try this just for you to see the txt data:

var info = $.parseJSON(data);
 alert(info);
answered Nov 21, 2012 at 8:28

4 Comments

Thanks Sir, but what i want is server-side parsing ... thanks again.
use var js = JavaScriptSerializer.serialize(object), then use StringBuilder.append(js);
yep, i think that JavaScriptSerializer is my choice ! .. thanks
Ha! This is what I was looking for. +++++1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.