static void Main() {
    string json_data = "假装json数据";
    // 压缩 json 数据
    string json_data = JsonCompress(json_data);
}

public static string JsonCompress(string json)
{
    StringBuilder sb = new StringBuilder();
    using (StringReader reader = new StringReader(json))
    {
        int ch = -1;
        int lastch = -1;
        bool isQuoteStart = false;
        while ((ch = reader.Read()) > -1)
        {
            if ((char)lastch != '\\' && (char)ch == '\"')
            {
                if (!isQuoteStart) isQuoteStart = true;
                else isQuoteStart = false;
            }
            if (!Char.IsWhiteSpace((char)ch) || isQuoteStart) sb.Append((char)ch);
            lastch = ch;
        }
    }
    return sb.ToString();
}

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

白祤星 微信支付

微信支付

白祤星 支付宝

支付宝