2

Possible Duplicate:
How to set formatting with JavaScriptSerializer when JSON serializing?

I'm using using System.Web.Script.Serialization to serialize some json. However, by default it makes ugly text without indentation.

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    var json = serializer.Deserialize<Dictionary<string,dynamic>>(s);

    // do something else to the json...

    //serialize the result
    string serialized = serializer.Serialize(json);
    // ugly text

I'm looking at the second overload and it takes a StringBuilder. I've not used these much. Can I use that to format pretty JSON? How would I do that in this context?

4

1 回答 1

2

imho, it's not possible to the JavaScriptSerializer how to format the ouput-string (in contradiction to XmlWriter for XmlSerializer)...

in my use-cases i ever decided to go with JSON.net, it's more powerfull, a lot of faster and for JSON ;)

于 2012-03-09T23:44:28.347 回答