将对象序列化为json .NET

时间:2013-08-21 08:22:59

标签: c# .net json

我必须将对象序列化为json字符串。这是我的代码:

                var addData = new {
                    nick = user.UserName,
                    imie = user.Firstname,
                    nazwisko = user.Surname,
                    wojewodztwo = user.State

                };

                var tempUser = new
                {
                    email = user.Email,
                    list = "12212",

                    state = 1,
                    confirm = 0,
                    custom_fields = addData

                };

              (...)

               var serializer = new JavaScriptSerializer();

               PostData = serializer.Serialize(tempUser);

结果是:

  

“{\” 电子邮件\ “:\” testowy@aa.pl \”,\ “列表\”:\ “12212 \”,\ “状态\”:1,\ “确认\”:0,\ “custom_fields \”:{\ “缺口\”:\ “JakisNicvk \”,\ “IMIE \”:\ “玛丽安\”,\ “nazwisko \”:\ “Mariański\”,\ “wojewodztwo \”:\”早点\ “}}”

看起来很糟糕。如何在没有\的情况下生成这样的json字符串? (主要对象的数组是custom_fields)?

  

{ “电子邮件”: “22@aa.pl”, “列表”: “12212”, “custom_fields”:{ “personalization_tag_1”:“值   1“,”personalization_tag_2“:”value 2“}}

问候。

0 个答案:

没有答案