我以UTF 8格式获取标题的json数据,然后如何解决它?

时间:2017-06-30 05:43:42

标签: ios iphone json utf-8

我得到了这个,

"title": "=?UTF-8?Q?=E2=80=9CUber=E2=80=99s_Complicit_Board=E2=80=9D_published_?= =?UTF-8?Q?in_Monday_Note_by_Jean-Louis_Gass=C3=A9e?=",  //here

我收到了以下josn数据,

 {

            "updated_at": "2017-06-27 13:45:23",
            "user_name": "noreply@medium.com",
            "first_name": "",
            "last_name": "",
            "email": "noreply@medium.com",
            "profile_pic": "https://secure.gravatar.com/avatar/1f98a43dd7d8f9568b557c7f03fe854e?s=80&r=g&d=identicon",
            "ticket_number": "AAAA-0000-0001",
            "id": 2,
            "title": "=?UTF-8?Q?=E2=80=9CUber=E2=80=99s_Complicit_Board=E2=80=9D_published_?= =?UTF-8?Q?in_Monday_Note_by_Jean-Louis_Gass=C3=A9e?=",
            "created_at": "2017-06-27 13:45:23",
            "department_name": "Support",
            "priotity_name": "Low",
            "priority_color": "#00a65a",
            "sla_plan_name": "Low",
            "help_topic_name": "Support query",
            "ticket_status_name": "Open",
            "department_id": 1,
            "user_dpt": null,
            "attachment": 0,
            "overdue_date": "2017-06-27 18:45:23"
        },
        {
            "updated_at": "2017-06-27 13:45:19",
            "user_name": "help@teamtreehouse.com",
            "first_name": "Treehouse",
            "last_name": "",
            "email": "help@teamtreehouse.com",
            "profile_pic": "https://secure.gravatar.com/avatar/84541406cf3c552347f8e31cef7d32ce?s=80&r=g&d=identicon",
            "ticket_number": "AAAA-0000-0000",
            "id": 1,
            "title": "=?UTF-8?Q?=C2=A0New_skills", // here also
            "created_at": "2017-06-27 13:45:19",
            "department_name": "Support",
            "priotity_name": "Low",
            "priority_color": "#00a65a",
            "sla_plan_name": "Low",
            "help_topic_name": "Support query",
            "ticket_status_name": "Open",
            "department_id": 1,
            "user_dpt": null,
            "attachment": 0,
            "overdue_date": "2017-06-27 18:45:19"
        }
    ]
}

2 个答案:

答案 0 :(得分:0)

您需要解码标题字符串,因此请检查以下代码。

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.GradientDrawable;

public class VoiceDrawable extends GradientDrawable {
    private static final float DEFAULT_LEVEL = 0.5f;

    private Paint levelPaint;
    private Paint viewPaint;
    private BitmapShader bitmapShader;
    private Matrix shaderMatrix;
    private float radius;

    private float level;

    public VoiceDrawable() {
        super();
        init();
    }

    private void init() {
        levelPaint = new Paint();
        levelPaint.setStyle(Paint.Style.FILL);

        viewPaint = new Paint();
        shaderMatrix = new Matrix();
    }

    public void setCornerRadius(float radius) {
        super.setCornerRadius(radius);

        this.radius = radius;
    }

    public void setVoice(float level) {
        this.level = level;

        invalidateSelf();
    }

    public void setLevelColor(int color) {
        levelPaint.setColor(color);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

        Rect rect = getBounds();
        if (bitmapShader == null) {
            initLevel(rect);
        }
        float scale = level == 0 ? 100 : (1 - level) / (1 - DEFAULT_LEVEL);
        shaderMatrix.setScale(1, scale, 0, DEFAULT_LEVEL);
        bitmapShader.setLocalMatrix(shaderMatrix);

        float rad = Math.min(radius, Math.min(rect.width(), rect.height()) * 0.5f);
        canvas.drawRoundRect(new RectF(rect), rad, rad, viewPaint);
    }

    private void initLevel(Rect rect) {
        Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawRect(rect.left, rect.top + rect.height() * (1 - DEFAULT_LEVEL), rect.right, rect.bottom, levelPaint);

        bitmapShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        viewPaint.setShader(bitmapShader);
    }
}

答案 1 :(得分:0)

这是来自RFC 2047的“编码字”编码。

这里有一个在线解码器:http://dogmamix.com/MimeHeadersDecoder/

libetpan可以解码它(参见mailmime_encoded_word_parse  在https://github.com/dinhviethoa/libetpan/blob/master/src/low-level/mime/mailmime_decode.c)。如果你只关心这个领域,这是非常重量级的。你可以自己编写一个基于RFC的解码器。