首页 > 解决方案 > Json反序列化和解码

问题描述

我得到外部 json 数据并想反序列化到我的集合:

        var responseString = await response.Content.ReadAsStringAsync();

        var result = JsonParse.ParseArrayCamelCase<ReadOnlyCollection<SureMdmGroup>>(responseString, "Groups");
        return result;

哪里ParseArrayCamelCase是:

    public static T ParseArrayCamelCase<T>(string txt, string arrayName)
    {
        JObject json = JObject.Parse(txt);
        var items = json[arrayName].ToString();
        JsonSerializerSettings serSettings = new JsonSerializerSettings
        {
            ContractResolver = new CamelCasePropertyNamesContractResolver(),
            Formatting = Formatting.Indented,
            StringEscapeHandling = StringEscapeHandling.EscapeHtml
        };
        return JsonConvert.DeserializeObject<T>(items, serSettings);
    }

它有效,但如果一些字符串像

E&amp;B Transport, LLC.

它应该转换为

E&B 运输有限责任公司。

我应该设置什么JsonSerializerSettings来解码字符串?

标签: c#jsondecodejson-deserialization

解决方案


推荐阅读