<?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[QJsonObject comparison]]></title><description><![CDATA[<p dir="auto">So, I have two objects of same length and order and I want to compare the values in my object using keys. I have written a rough code and I would like to know if it works or is there any other way that this could be done.<br />
I cannot use the qjsonobject equality method because even though the order and the keys are the same, the values might vary and I wish to point that difference out by iterating through my objects.</p>
<pre><code>if(bool(refobject.length()==testobject.length())==true)
   {
    QJsonObject::iterator i,j;
    for (i = refobject.begin(), j= testobject.begin(); 
                  i!=refobject.end()&amp;&amp;j!=testobject.end(); ++i,++j)
    {
    if(i.key()==j.key())
       {     
       if(i.value().isString() &amp;&amp; j.value().isString())
       { 
           if(i.value()==j.value())
           {
             //display i and j
           }
           else 
           {
            //display them in a different colour 
           }
           
         }
       else if(i.value().isArray()&amp;&amp; j.value().isArray())
       {
         //iterate and compare
       }
       else if(i.value().isObject() &amp;&amp; j.value().isObject())
       {
          //check if there are strings or integers or array and work accordingly 
       }
       else if(i.value().isDouble() &amp;&amp; j.value().isDouble())
       {
           if(i.value()==j.value())
           {
             //display i and j
           }
           else 
           {
              //display them in a different colour 
           }
           
       }

    }
}
}

else{//display message that you cannot compare them}
}
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/113293/qjsonobject-comparison</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 15:00:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/113293.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Apr 2020 08:32:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QJsonObject comparison on Sat, 04 Apr 2020 09:35:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Thanks a lot for your insight!</p>
]]></description><link>https://forum.qt.io/post/586583</link><guid isPermaLink="true">https://forum.qt.io/post/586583</guid><dc:creator><![CDATA[rosh7]]></dc:creator><pubDate>Sat, 04 Apr 2020 09:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to QJsonObject comparison on Sat, 04 Apr 2020 09:16:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rosh7">@<bdi>rosh7</bdi></a><br />
In principle your iteration algorithm looks OK.  Since you do not alter either object you could use <a href="https://doc.qt.io/qt-5/qjsonobject-const-iterator.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qjsonobject-const-iterator.html</a> instead of <code>QJsonObject::iterator</code>, to maybe gain an extra mark :)</p>
<p dir="auto">In your <code>isObject()</code> case, and also in your <code>isArray()</code> case where you note you will need to iterate and compare, you will need to <em>call this function again recursively</em> if you encounter an <code>isObject()</code> (i.e. a <code>QJsonObject</code>).  In your other post, you showed your input file, and IIRC it had JSON objects and/or arrays at the <em>top</em> level(s), not <em>only</em> at the bottom, leaf levels.  So the recursion will be needed to walk <em>down</em> the tree.</p>
]]></description><link>https://forum.qt.io/post/586579</link><guid isPermaLink="true">https://forum.qt.io/post/586579</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 04 Apr 2020 09:16:22 GMT</pubDate></item></channel></rss>