user88284: I am getting a json object from aws iot MQTT. Assuming that json from aws is {status:opened}.
Here is my code.
#include <ArduinoJson.h>
void messageHandler(char *topic, byte *payload, unsigned int length)
{
  StaticJsonDocument<32> doc;
  deserializeJson(doc, payload);
  const char *status = doc["status"];
  Serial.println(status);//opened
  if (status == "opened")
  {
    Serial.println("door is opened");//not excute
  }
  else if (status == "closed")
  {
    Serial.println("door is closed");
  }
}

Why the if condition is not being excute?

user3430: That's one of the peculiarities of the C language: the == operator compares the string addresses, not their content. It makes sense when you think of them as pointers, but it can be confusing for beginners.
To fix this, you can use strcmp() like so:
if (strcmp(status,"opened") == 0)
Alternatively, you can change the type of status to JsonVariant, like so:
JsonVariant status = doc["status"]
It works with JsonVariant because I overloaded the == operator to support string comparison.

88284: <p>I am getting a json object from aws iot MQTT. Assuming that json from aws is {status:opened}.
Here is my code.</p>
<pre><code>#include &lt;ArduinoJson.h&gt;
void messageHandler(char *topic, byte *payload, unsigned int length)
{
  StaticJsonDocument&lt;32&gt; doc;
  deserializeJson(doc, payload);
  const char *status = doc[&quot;status&quot;];
  Serial.println(status);//opened
  if (status == &quot;opened&quot;)
  {
    Serial.println(&quot;door is opened&quot;);//not excute
  }
  else if (status == &quot;closed&quot;)
  {
    Serial.println(&quot;door is closed&quot;);
  }
}
</code></pre>
<p>Why the if condition is not being excute?</p>
 3430: <p>That's one of the peculiarities of the C language: the <code>==</code> operator compares the string addresses, not their content. It makes sense when you think of them as pointers, but it can be confusing for beginners.</p>
<p>To fix this, you can use <code>strcmp()</code> like so:</p>
<p><code>if (strcmp(status,&quot;opened&quot;) == 0)</code></p>
<p>Alternatively, you can change the type of <code>status</code> to <code>JsonVariant</code>, like so:</p>
<p><code>JsonVariant status = doc[&quot;status&quot;]</code></p>
<p>It works with <code>JsonVariant</code> because I overloaded the <code>==</code> operator to support string comparison.</p>
