如何在C#中将json对象转换为字符串?

时间:2014-04-30 06:36:24

标签: c# json

{
    "memberRegistration": [{
        "reference_mobile": "1",
        "reference_name": "r1",
        "member_id": "12"
    }, {
        "reference_mobile": "2",
        "reference_name": "r2",
        "member_id": "12"
    }, {
        "reference_mobile": "3",
        "reference_name": "r3",
        "member_id": "12"
    }, {
        "reference_mobile": "4",
        "reference_name": "r4",
        "member_id": "12"
    }]
}

我有一个如上所示的json对象。如何将其转换为字符串?
我想要这种格式的字符串;

@"[{""reference_mobile"":""1"",""reference_name"":""r1"",""member_id"":""12""},"+@"{""reference_mobile"":""2"",""reference_name"":""r2"",""member_id"":""12""},"+@"{""reference_mobile"":""3"",""reference_name"":""r3"",""member_id"":""12""},"+@"{""reference_mobile"":""4"",""reference_name"":""r4"",""member_id"":""12""}]";

请帮我这样做。

1 个答案:

答案 0 :(得分:1)

使用JavaScriptSerializer

string json = new JavaScriptSerializer().Serialize(YourJson);