I'm attempting to read JSON from a configuration file using file.readAll(). I can open and perform the read, but can't figure out how to convert the ArrayBuffer to a string or ultimately I want to make use of the JSON in the file.
Considering the file "foo.json" in my data folder:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"value"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"things"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I'm reading it using the following code:
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">readConfig</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> file <SPAN class="operator token">=</SPAN> AppFramework<SPAN class="punctuation token">.</SPAN><SPAN class="token function">file</SPAN><SPAN class="punctuation token">(</SPAN>AppFramework<SPAN class="punctuation token">.</SPAN>userHomePath <SPAN class="operator token">+</SPAN> <SPAN class="string token">"/ArcGIS/Runtime/Data/foo.json"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>file<SPAN class="punctuation token">.</SPAN>exists<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>file<SPAN class="punctuation token">.</SPAN><SPAN class="token function">open</SPAN><SPAN class="punctuation token">(</SPAN>File<SPAN class="punctuation token">.</SPAN>OpenModeReadOnly<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> data <SPAN class="operator token">=</SPAN> file<SPAN class="punctuation token">.</SPAN><SPAN class="token function">readAll</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// get the json?</SPAN>
file<SPAN class="punctuation token">.</SPAN><SPAN class="token function">close</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>but I can't seem to get the text or JSON from the binary data that readAll() returns. It looks like I could use a loop and readLine() which returns a string, then check for file.atEnd, but it seems like there must be a better way.
Obviously I'm new on the QML/JS journey and would sure appreciate a push in the right direction. Thanks in advance!