我必须将对象序列化为 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);
这是结果:
"{\"email\":\"testowy@aa.pl\",\"list\":\"12212\",\"state\":1,\"confirm\":0,\"custom_fields\ ":{\"nick\":\"JakisNicvk\",\"imie\":\"Marian\",\"nazwisko\":\"Mariański\",\"wojewodztwo\":\"małopolskie\" }}”
看起来很糟糕。我怎样才能生成这样的json字符串,没有\
?(并且主要对象在哪里有数组custom_fields
)?
{"email":"22@aa.pl","list":"12212","custom_fields":{"personalization_tag_1":"value 1","personalization_tag_2":"value 2"}}
问候。