我试图解析一个jsonObject,似乎无法得到它,这是我得到的.
json = (json data)
JsonParser parser = new JsonParser();
JsonObject rootObj = parser.parse(json).getAsJsonObject();
JsonObject paymentsObject = rootObj.getAsJsonObject("payments");
for(JsonObject pa : paymentsObject){
String dateEntered = pa.getAsJsonObject().get("date_entered").toString();
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个不适用于键入我缺少的东西的foreach.我尝试了不同的方法,但似乎无法得到它.谢谢
JSON
{
"Name":"Test 2",
"amountCollected":"1997",
"payments":[
{
"quoteid":"96a064b9-3437-d536-fe12-56a9caf5d881",
"date_entered":"2016-05-06 08:33:48",
"amount":"1962",
},
{
"quoteid":"96a064b9-3437-d536-fe12-56a9caf5d881",
"date_entered":"2016-05-06 08:33:08",
"amount":"15",
},
{
"quoteid":"96a064b9-3437-d536-fe12-56a9caf5d881",
"date_entered":"2016-05-06 03:19:08",
"amount":"20",
}
]
}
Run Code Online (Sandbox Code Playgroud) 基本上我只想循环遍历一个字符串拉出每个字符,每个字符必须是const char*类型,所以我可以将它传递给一个函数.这是一个例子.谢谢你的帮助.
string thestring = "abc123";
const char* theval;
string result;
for(i = 0; i < thestring.length(); i++){
theval = thestring[i]; //somehow convert this must be type const char*
result = func(theval);
}
Run Code Online (Sandbox Code Playgroud) 什么是检查日期格式的好方法,我希望格式为2011-12-08 16:59:18我有提升将使用正则表达式是最好的方式去或是否有一些C++方式来做它.提前致谢.这里有一些测试条件,但不限于这些.
所以例如某人进入
2011-2-08 16:59:18 //incorrect date month needs to have 2 digits 02
2011-02-08 16:9:18 //incorrect minuets needs to have 2 digits 09
2011-02-0X 16:09:18 //incorect alpha character for day no alpha except - and :
2011-12-08 16:59:18 // correct
Run Code Online (Sandbox Code Playgroud) 我需要比较2个字符串日期,以查看一个日期是否晚于另一个日期.两个日期的日期格式位于底部.我可以重新安排这个最简单的事情.我有提升但不一定是,我已经通过这么多的例子,似乎无法将我的大脑包围起来让它发挥作用.提前谢谢基本上我想要的
2012-12-06 14:28:51
if (date1 < date2) {
// do this
}
else {
// do that
}
Run Code Online (Sandbox Code Playgroud) 这是我如何生成我想要添加1年的日期.提前致谢.
char tmpbuf[128];
time_t ltime;
struct tm *today;
stringstream reD;
string todayDate;
time( <ime );
today = localtime( <ime );
strftime( tmpbuf, 128,"%Y-%m-%d_%H:%M:%S", today );
reD << tmpbuf;
reD >> todayDate;
boost::replace_all(todayDate, "_", " ");
cout << todayDate << endl;
Run Code Online (Sandbox Code Playgroud)
好吧我已决定使用提升,因为它会更容易添加天,所以2个例子我需要一个添加1年,一个添加14天,继承人我有这样的票价
#include "boost/date_time.hpp"
#include "boost/date_time/local_time/local_time.hpp"
using namespace boost::posix_time;
using namespace boost::local_time;
int main(){
local_date_time t = local_sec_clock::local_time(time_zone_ptr());
local_time_facet* lf(new local_time_facet("%Y-%m-%d_%H:%M:%S"));
std::cout.imbue(std::locale(std::cout.getloc(), lf));
std::cout << t << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑将时间放入字符串
stringstream reD;
reD.imbue(locale(reD.getloc(), lf));
reD << t;
bthis = …Run Code Online (Sandbox Code Playgroud) 下面的函数运行,但每次运行程序时总是返回相同的数字.有没有办法在每次运行程序时生成不同的随机数?
int getrand(int min,int max){
int rnum = rand()%(max-min)+min;
return rnum;
}
Run Code Online (Sandbox Code Playgroud)