<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Derek,<br>
<br>
see ovms_metrics.h:<br>
<br>
<tt>/**</tt><tt><br>
</tt><tt> * OvmsMetricVector<type>: metric wrapper for
std::vector<type></tt><tt><br>
</tt><tt> * - string representation as comma separated values</tt><tt><br>
</tt><tt> * - TODO: escaping / string encoding for non-numeric
types<br>
…<br>
</tt><br>
The template hasn't been specialized for non-numeric types yet,
simply as they haven't been needed up to now.<br>
<br>
You're welcome to add this template specialization.<br>
<br>
DukPush() works without specialization because the DukContext.Push()
method has specializations for the most common types, and Duktape
knows about the types added to the array.<br>
<br>
AsString() and SetValue(string) need special handling for string
vectors (quotes & escapes).<br>
<br>
AsJSON() is used for the websocket transport of metrics. If you can
use json_encode() for AsString(), AsJSON() doesn't need additional
handling, but you'll need to add a string parser to SetValue(), as
std::quoted cannot handle JSON encoded strings.<br>
<br>
Regards,<br>
Michael<br>
<br>
<br>
<div class="moz-cite-prefix">Am 06.09.20 um 12:07 schrieb Derek
Caudwell:<br>
</div>
<blockquote type="cite"
cite="mid:CAKUcfWHyjy4djgMJtk4DeXMnnJMMNW2yMqGEPvBwjRwNY74gDA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I am trying to resolve the ovms web interface throwing an
"undefined" error because the following metric is defined
with OvmsMetricVector<string> and does not get quoted
when parsed to JSON.parse(ev.data) in ovms.js.</div>
<div><br>
</div>
<div>Output from console error log:</div>
<div>"xnl.v.c.duration.label":[full.l2,full.l1,full.l0,range.l2,range.l1,range.l0]<br>
</div>
<div><br>
</div>
<div>However, when using
JSON.print(OvmsMetrics.GetValues("xnl.v.c.duration.label")) a
properly formed json string is returned:</div>
<div> "xnl.v.c.duration.label": [<br>
"full.l2",<br>
"full.l1",<br>
"full.l0",<br>
"range.l2",<br>
"range.l1",<br>
"range.l0"<br>
]<br>
</div>
<div><br>
</div>
<div>Can this be corrected at the ev.data source or use
JSON.print on ev.data before parsing it?</div>
<div><br>
</div>
<div>Kind regards</div>
<div>Derek</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
OvmsDev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OvmsDev@lists.openvehicles.com">OvmsDev@lists.openvehicles.com</a>
<a class="moz-txt-link-freetext" href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">http://lists.openvehicles.com/mailman/listinfo/ovmsdev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26</pre>
</body>
</html>