vc没有自带的json库,所以分享一下如何使用该库http://download.csdn.net/detail/moruite/4104704
1. json.h头文件包含了如下api
#ifndef cpptl_json_h_included
# define cpptl_json_h_included
# include "forwards.h"
# include
# include
# ifndef json_use_cpptl_smallmap
# include
2. 如何打包json数据
json::value rootnode;
json::value listnode;
for(i=0;i
3. 如何解析json数据
json::value result;
json::reader reader;
if(!reader.parse((lptstr)(lpctstr)strcontent,result)){
return false;
}
//m_machineid.format("%s",result["machineid"]);
m_machineid=result["machineid"].ascstring();
m_tableid=result["tableid"].ascstring();
m_streamline=result["streamline"].ascstring();
m_personcount=result["personcount"].ascstring();
double totalprice=0;
json::value list=result["dishitem"];
if(list.isarray()){
int count=list.size();
json::value element;
for(int i=0;idishunit=element["dishunit"].ascstring();
pitem->dishmake=element["dishmake"].ascstring();
pitem->dishid=element["dishid"].ascstring();
pitem->dishname=element["dishname"].ascstring();
pitem->dishnum.format("%d",element["dishnum"].asint());
pitem->dishprice=element["dishprice"].ascstring();
totalprice =atof(element["dishprice"].ascstring());
m_items.addtail(pitem);
}
}
m_price.format("%.2f",totalprice);