<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Decode an Array of Array</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98930/decode-an-array-of-array</link><description>Hello, 
 I&amp;#39;m new in Zephyr and it past almost 30 years since I program in C. 
 I having some problems (like 5 days) trying to parse a json in zephyr but I can&amp;#39;t figure it out. 
 
 This is the json I want to decode: 
 
 And the Structers: 
 
 Does anyone</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Apr 2023 13:11:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98930/decode-an-array-of-array" /><item><title>RE: Decode an Array of Array</title><link>https://devzone.nordicsemi.com/thread/421513?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2023 13:11:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7358fb23-da58-47b9-88b0-46d474579b65</guid><dc:creator>maadaf</dc:creator><description>&lt;p&gt;Thank you Marte. I will try it as soon as possible.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Maadaf&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decode an Array of Array</title><link>https://devzone.nordicsemi.com/thread/421504?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2023 12:45:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae28e440-e544-40f9-835e-1cf2ed899ec9</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I recommend using the cJSON library, which is a simple JSON parses, instead of doing everything yourself.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This library is used in multiple of our nRF9160 samples, for example,&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/nrf/samples/nrf9160/aws_iot/README.html"&gt;AWS IoT&lt;/a&gt;, so you can look there for an example of how to use&amp;nbsp;it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Make sure to also enable the library in prj.conf:&lt;/p&gt;
&lt;p&gt;CONFIG_CJSON_LIB=y&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decode an Array of Array</title><link>https://devzone.nordicsemi.com/thread/421427?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2023 09:23:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5c58ad9-21bc-431d-be75-1ebbab19bb7a</guid><dc:creator>maadaf</dc:creator><description>&lt;p&gt;I&amp;#39;m Sorry my mistake. That&amp;#39;s not the last one I&amp;#39;ve been trying. The last attempt was:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="json"&gt;{
	&amp;quot;schedules&amp;quot;:[{
		&amp;quot;valve&amp;quot;:&amp;quot;v1&amp;quot;,
		&amp;quot;schedule_res&amp;quot;:[{
			&amp;quot;starthour&amp;quot;:&amp;quot;0600&amp;quot;,
			&amp;quot;activetime&amp;quot;:30,
			&amp;quot;days&amp;quot;:&amp;quot;1111111&amp;quot;
		},{
			&amp;quot;starthour&amp;quot;:&amp;quot;1900&amp;quot;,
			&amp;quot;activetime&amp;quot;:20,
			&amp;quot;days&amp;quot;:&amp;quot;1110111&amp;quot;
		}],[{
			&amp;quot;valve&amp;quot;:&amp;quot;v2&amp;quot;,
			&amp;quot;schedule_res&amp;quot;:[{
				&amp;quot;starthour&amp;quot;:&amp;quot;0800&amp;quot;,
				&amp;quot;activetime&amp;quot;:10,
				&amp;quot;days&amp;quot;:&amp;quot;1111100&amp;quot;
			},{
				&amp;quot;starthour&amp;quot;:&amp;quot;2300&amp;quot;,
				&amp;quot;activetime&amp;quot;:50,
				&amp;quot;days&amp;quot;:&amp;quot;1110110&amp;quot;
			}]
		}]
	}]
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct schedule {
	const char *starthour;
	int activetime;
	const char *days;
};

struct schedule_v {
	const char *valve;
	struct schedule schedule_res[2];
	size_t num_elements;
};

struct schedule_ctl {
	struct schedule_v schedules[2];
	size_t num_elements1;
};

static const struct json_obj_descr schedule_descr[] = {
	JSON_OBJ_DESCR_PRIM(struct schedule, starthour, JSON_TOK_STRING),
	JSON_OBJ_DESCR_PRIM(struct schedule, activetime, JSON_TOK_NUMBER),
	JSON_OBJ_DESCR_PRIM(struct schedule, days, JSON_TOK_STRING),
};

static const struct json_obj_descr schedule_ctl_descr[] = {
	JSON_OBJ_DESCR_PRIM(struct schedule_v, valve, JSON_TOK_STRING),
	JSON_OBJ_DESCR_OBJ_ARRAY(struct schedule_v, schedule_res, 10, num_elements, schedule_descr, ARRAY_SIZE(schedule_descr)),
};

static const struct json_obj_descr schedule_ctl_[] = {
	JSON_OBJ_DESCR_OBJ_ARRAY(struct schedule_ctl, schedules, 10, num_elements1, schedule_ctl_descr, ARRAY_SIZE(schedule_ctl_descr)),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tryied so many variations already. My problem are with the zephyr struct definitions.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Decode an Array of Array</title><link>https://devzone.nordicsemi.com/thread/421425?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2023 09:18:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3679117f-6fbe-46b3-ab4c-e8cee5c1bec8</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Neither &lt;em&gt;const char&lt;/em&gt; nor &lt;em&gt;const&lt;/em&gt; is applicable for a &lt;em&gt;string&lt;/em&gt; constant.&lt;/p&gt;
&lt;p&gt;You might wanted to use &amp;quot;const char * &amp;quot; in both cases. That star is important as it will need to be a &lt;em&gt;pointer&lt;/em&gt; to a character array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>