String str = {"timestamp": "2023-02-08 16-37-31" ,"cpcb_device": [{"Station" : "832","Para": [{"tag_name": "COD","tag_value": "35.5","tag_unit": "mg/l"},{"tag_name": "BOD","tag_value": "13.7","tag_unit": "mg/l"},{"tag_name": "TSS","tag_value": "24.8","tag_unit": "mg/l"},{"tag_name": "pH","tag_value": "6.5","tag_unit": "pH"}]}]}
-
2it looks like JSON format. try the ArduinoJson libraryJuraj– Juraj ♦2023-02-11 17:10:42 +00:00Commented Feb 11, 2023 at 17:10
-
Using json, it shows derealization error., because string is changed every time from its positionKaran Bawadekar– Karan Bawadekar2023-02-11 17:14:01 +00:00Commented Feb 11, 2023 at 17:14
-
1what is " changed every time from its position"?Juraj– Juraj ♦2023-02-11 17:16:58 +00:00Commented Feb 11, 2023 at 17:16
-
Input string is changed as POST / HTTP/1.1 Host: 192.168.0.197 User-Agent: libcurl-agent/1.0 Accept: / Content-Length: 144 Content-Type: application/x-www-form-urlencoded {"timestamp": "2023-02-08 16-37-33" ,"cpcb_device": [{"Station" : "833","Para": [{"tag_name": "Flow","tag_value": "2.0","tag_unit": "m3/hr"}]}]}Karan Bawadekar– Karan Bawadekar2023-02-11 17:20:02 +00:00Commented Feb 11, 2023 at 17:20
-
use the HTTPClient library for the POST requestJuraj– Juraj ♦2023-02-11 17:21:08 +00:00Commented Feb 11, 2023 at 17:21
|
Show 3 more comments
1 Answer
You can use substring() and indexOf() to get parts of the string at certain positions. for example:
String test = "timestamp: 123 value: test";
int val = test.indexOf("timestamp:"); //gives you the index for the beginning of "timestamp:"
int start = test.indexOf(" ", val)+1; //get index of the space starting at our 'val' index
int end = test.indexOf(" ", start); //get index of the next space, we added 1 to the previous value so it doesn't pick up the first space
timestamp = test.substring(start, end); //get the characters between these two index values
Try it out and see how it works for you, obviously getting the index of separating characters that make more sense, such as a comma or colon rather than a space.
Also you could do it like this:
String search = "timestamp:";
int start = test.indexOf(search)+search.length();
//etc...