JSON data format, here's a basic example:
{"Name": "LGH"}
In C + +, I use a function to combine specific data into JSON
1 voidToJson (intcount) {2 Charjson[ -];3 Charresult[ $] ="{";4 Char* Temp ="\ "Count\"";5 Char* Temp_1 ="\"";6 Char* Temp_2 ="}";7 //cout<<count;8_itoa (Count,json,Ten);9 strcat (result,temp);Tenstrcat (Result,":"); One strcat (result,temp_1); A strcat (Result,json); - strcat (result,temp_1); - strcat (result,temp_2); the //cout<< "tojson=" <<result<<endl; -SendMessage (result);//custom functions, transferring data -}
Notice that the transfer function inside of me is chosen to execute inside, the reason is that the return of char* result by ToJson will cause memory overflow, and later do so to become possible.
Here is the Sendmassage () function
1 voidSendMessage (Char*information) {2 //Powered by LGH-20143 //Char url_for_lgh_connect_database[200000]= "http://linguanh.nat123.net/updata.php?id=";//URL4 Charurl_for_lgh_connect_database[200000]="http://localhost:8080/C++_face.php?DB=";//links5 Const Char*x="From_af";6 7 //information= (char*) malloc (sizeof (char) * (102400)); 8 strcat (url_for_lgh_connect_database,information);9WCHAR exchange_text_from_url[ the],exchange_text_from_x[ the];//wide character char, if burst red, modify the encoding of the item to be multibyte.TenLPCWSTR py =Exchange_text_from_url; OneLPCWSTR PZ =exchange_text_from_x; A -MultiByteToWideChar (0,0, X,-1, Exchange_text_from_x, -);//WCHAR to LPCWSTR, conversion - theMultiByteToWideChar (0,0, Url_for_lgh_connect_database,-1, Exchange_text_from_url, the ); - - if(Internetattemptconnect (0) !=error_success) { -cout<<"your computer cannot connect to the Internet, please turn on the networking feature. "<<Endl; +cout<<"(Your computer can not connect the internet,please try to fix it!)"<<Endl; - } + Else{ A //header file WinInet API function, access to a link at if(InternetOpenUrl (InternetOpen (x,internet_open_type_direct,null,null,null), Url_for_lgh_connect_database,null, null,null,null) = =NULL) { - SendMessage (information); - } - Else{ - //cout<< "result=" <<Information<<endl; - //cout<<url_for_lgh_connect_database<<endl; incout<<"The information has been sent to the LGH database. (The information have been sent to Lgh ' s database.)"<<Endl; - } to } + //Free (information); - //Information=null; the}
C + + makes JSON data and transmits it to server-side PHP