我正在尝试使用velocity模板解析json。这是我的json字符串,
std::char_traits<>::compare
这是我的速度模板,
{\n \"firstName\": \"Tom\",\n \"lastName\": \"Geller\",\n \"department\": \"Retail\",\n \"manager\": \"Steve\",\n \"joiningDate\": \"03/08/2011\",\n \"employees\": [\n {\n \"firstName\": \"Paul\",\n \"lastName\": \"Balmer\",\n \"department\": \"Retail\",\n \"manager\": \"Tom Geller\",\n \"joiningDate\": \"06/21/2014\"\n },\n {\n \"firstName\": \"Eric\",\n \"lastName\": \"S\",\n \"department\": \"Retail\",\n \"manager\": \"Tom Geller\",\n \"joiningDate\": \"09/13/2014\"\n }\n ]\n}
这是打印的输出。它没有打印报告员工,
$firstName $lastName belongs to $department Department.
His manager is $manager and joining date is $joiningDate.
Employees reporting to him are,
#foreach( $employee in $employees )
$employee.firstName $employee.lastName
#end
这是java代码,
Tom Geller belongs to Retail Department.
His manager is Steve and joining date is 03/08/2011.
Employees reporting to him are,
答案 0 :(得分:1)
由于$employees
是JSONArray,我看到两个可能的原因:
答案 1 :(得分:0)
您可以使用json库
将json数据转换为Map / List形式。