-1
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"}]}]}
8
  • 2
    it looks like JSON format. try the ArduinoJson library Commented Feb 11, 2023 at 17:10
  • Using json, it shows derealization error., because string is changed every time from its position Commented Feb 11, 2023 at 17:14
  • 1
    what is " changed every time from its position"? Commented 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"}]}]} Commented Feb 11, 2023 at 17:20
  • use the HTTPClient library for the POST request Commented Feb 11, 2023 at 17:21

1 Answer 1

0

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...
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.