|
@@ -416,7 +416,7 @@ inline StringBuffer &appendXMLTag(StringBuffer &xml, const char *tag, const char
|
|
|
|
|
|
inline StringBuffer &delimitJSON(StringBuffer &s, bool addNewline=false, bool escapeNewline=false)
|
|
|
{
|
|
|
- if (s.length() && !strchr("{[:n\n", s.charAt(s.length()-1))) //'n' or '\n' indicates already formatted with optionally escaped newline
|
|
|
+ if (s.length() && !strchr("{ [:,n\n", s.charAt(s.length()-1))) //'n' or '\n' indicates already formatted with optionally escaped newline
|
|
|
{
|
|
|
s.append(",");
|
|
|
if (addNewline)
|
|
@@ -430,10 +430,17 @@ inline StringBuffer &delimitJSON(StringBuffer &s, bool addNewline=false, bool es
|
|
|
jlib_decl StringBuffer &encodeJSON(StringBuffer &s, const char *value);
|
|
|
jlib_decl StringBuffer &appendJSONName(StringBuffer &s, const char *name);
|
|
|
|
|
|
+inline StringBuffer &appendJSONNameOrDelimit(StringBuffer &s, const char *name)
|
|
|
+{
|
|
|
+ if (name && *name)
|
|
|
+ return appendJSONName(s, name);
|
|
|
+ return delimitJSON(s);
|
|
|
+}
|
|
|
+
|
|
|
template <typename type>
|
|
|
inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, type value)
|
|
|
{
|
|
|
- appendJSONName(s, name);
|
|
|
+ appendJSONNameOrDelimit(s, name);
|
|
|
return s.append(value);
|
|
|
}
|
|
|
|
|
@@ -441,14 +448,14 @@ inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, type val
|
|
|
template <>
|
|
|
inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, bool value)
|
|
|
{
|
|
|
- appendJSONName(s, name);
|
|
|
+ appendJSONNameOrDelimit(s, name);
|
|
|
return s.append((value) ? "true" : "false");
|
|
|
}
|
|
|
|
|
|
template <>
|
|
|
inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, const char *value)
|
|
|
{
|
|
|
- appendJSONName(s, name);
|
|
|
+ appendJSONNameOrDelimit(s, name);
|
|
|
if (!value)
|
|
|
return s.append("null");
|
|
|
return encodeJSON(s.append('"'), value).append('"');
|
|
@@ -457,14 +464,14 @@ inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, const ch
|
|
|
template <>
|
|
|
inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, long value)
|
|
|
{
|
|
|
- appendJSONName(s, name);
|
|
|
+ appendJSONNameOrDelimit(s, name);
|
|
|
return s.appendlong(value);
|
|
|
}
|
|
|
|
|
|
template <>
|
|
|
inline StringBuffer &appendJSONValue(StringBuffer& s, const char *name, unsigned long value)
|
|
|
{
|
|
|
- appendJSONName(s, name);
|
|
|
+ appendJSONNameOrDelimit(s, name);
|
|
|
return s.appendulong(value);
|
|
|
}
|
|
|
|