1
/* $Id: json_test.c 4761 2014-02-24 09:02:44Z nanang $ */
3
* Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#define THIS_FILE "json_test.c"
25
#include <pjlib-util/json.h>
27
#include <pj/string.h>
29
static char json_doc1[] =
35
\"String\": \"A\\tString with tab\",\
41
\"Array1\": [116, false, \"string\", {}],\
52
\"Array1\": [116, false, \"string\"]\
56
static int json_verify_1()
64
pool = pj_pool_create(mem, "json", 1000, 1000, NULL);
66
size = (unsigned)strlen(json_doc1);
67
elem = pj_json_parse(pool, json_doc1, &size, &err);
69
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() parse error"));
73
size = (unsigned)strlen(json_doc1) * 2;
74
out_buf = pj_pool_alloc(pool, size);
76
if (pj_json_write(elem, out_buf, &size)) {
77
PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() write error"));
81
PJ_LOG(3,(THIS_FILE, "Json document:\n%s", out_buf));
82
pj_pool_release(pool);
86
pj_pool_release(pool);