So as the title says I want to find a number, called "value" in a .txt file and replace it with another number. (A number that is 10% bigger). The text file looks like this:
"thisisaname":{"last_updated":1464076848,"quantity":123,"value":938},
"thisisaname":{"last_updated":1464076848,"quantity":50,"value":3521}, etc...
The file is packed with the name and the info within the brackets. I want to look for "value", and read the numbers after it, store it, change it, and replace it. I do not know where to start.
I am not sure how to look for "value" and read the numbers after it. I can replace it, and store it in a variable.
(Question^)
One idea I had was read all the lines, and store it in a string. Look for the word "value" in the string, go forward 2 letters, and read the rest as long as it is of int type. Then stop, save the numbers, store it, replace, and repeat.
(Not sure if working^, neither sure if easiest way)
Yea I did use a json parser and it looks so organized lol. Anyways, I havent workind with JSON and dont know how to modify the value? Any tips on where to start? Otherwise I guess I'll just learn it, or atleast try. Thank you :)
JSON is the file format. There are various different JSON parsing libraries you can use to read and write data in that format. Bascially, you'll need to:
- use a JSON library to read the data from the file into an object defined by the library
- change the value of the data in the object
- use the JSON library to write the modified data back to the file
The functions you'll use for this will depend on which library you use.