<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QImage from JSON double encoded data]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm receiving an image through JSON.</p>
<p dir="auto">I cannot share file data due char limitation. Please download it on WeTransfer:</p>
<p dir="auto"><a href="https://we.tl/t-Z3tgCT7NSK" target="_blank" rel="noopener noreferrer nofollow ugc">https://we.tl/t-Z3tgCT7NSK</a></p>
<p dir="auto">It seems that the image has been double encoded: "Windows-1252" -&gt; "UTF-8" -&gt; "base64".</p>
<p dir="auto">How do I revert the double encoding?</p>
<pre><code>QFile qFile("image.json");
if (qFile.open(QIODeviceBase::ReadOnly))
{
	QTextStream qStream(&amp;qFile);
	QByteArray qBuffer = qStream.readAll().toUtf8();
	QJsonParseError* pqError = nullptr;
	QJsonDocument qJsonDoc = QJsonDocument::fromJson(qBuffer, pqError);
	if (!qJsonDoc.isNull())
	{
		QJsonObject qJsonObject = qJsonDoc.object();
		if (qJsonObject.contains("IMG"))
		{
                    QString base64 = qJsonObject.value("IMG").toString();

                    //Here I need to do the double decoding
                    QImage qImage;
		}
	}
}
</code></pre>
<p dir="auto">Regards,</p>
]]></description><link>https://forum.qt.io/topic/164450/qimage-from-json-double-encoded-data</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 19:19:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164450.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Mar 2026 17:38:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QImage from JSON double encoded data on Thu, 19 Mar 2026 15:12:32 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Finally I found a solution. It seems that the error starts with the data extracted from a Database that is bad encoded. The solution:</p>
<pre><code>QString qImgB64 = qJsonObject.value("IMG").toString();

// Base64 → "corrupted bytes"
QByteArray qDecoded = QByteArray::fromBase64(qImgB64.toLatin1());

// UTF-8
QString utf8Text = QStringDecoder(QStringDecoder::Utf8)(qDecoded);

// Convert to CP1252
QStringEncoder encoder(QStringEncoder::System); // or Windows-1252 "QStringEncoder encoder("Windows-1252");"
QByteArray qJpeg = encoder(utf8Text);

// Load into image
QImage qImage;
bool ok = qImage.loadFromData(qJpeg);
</code></pre>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/post/837192</link><guid isPermaLink="true">https://forum.qt.io/post/837192</guid><dc:creator><![CDATA[ollarch]]></dc:creator><pubDate>Thu, 19 Mar 2026 15:12:32 GMT</pubDate></item><item><title><![CDATA[Reply to QImage from JSON double encoded data on Wed, 18 Mar 2026 19:39:09 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I haven't used that class yet but I think you are looking for <a href="https://doc.qt.io/qt-6/qstringdecoder.html" target="_blank" rel="noopener noreferrer nofollow ugc">QStringDecoder</a>.</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/837168</link><guid isPermaLink="true">https://forum.qt.io/post/837168</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 18 Mar 2026 19:39:09 GMT</pubDate></item></channel></rss>