0

I want to use eclipse and java to make a program that can parse json files in java only.

For example, I want to change a value in JSON to another value every second.

I know the jsonparse function in javascript, but to carry it over through scriptengine alone seems like a bad solution.

I also know that I can use Apache IO to read a file to string and then edit the string and read the file back, but it doesn't seem efficient.

Is there an effective way to modify values in a JSON.php file?

Here is a JSON.php file that I have.

[{"color": "red waves-effect waves-light", "value": "0", "activator": "null"}]

Here is a part of my java program that does the text editing.

String attentionVs = "" + attentionV;
File fileattentionV = new File("attentionV.php");
String fileContext2 = FileUtils.readFileToString(fileattentionV);
fileContext2 = attentionVs;
FileUtils.write(fileattentionV, fileContext2);

String meditationVs = "" + meditationV;
File filemeditationV = new File("meditationV.php");
fileContext2 = FileUtils.readFileToString(filemeditationV);
fileContext2 = meditationVs;
FileUtils.write(filemeditationV, fileContext2);

Thanks for your help!

  • 2
    JSON.php? When did Json files have php extension? – Ikari Mar 25 '16 at 03:11
  • I agree- this is very confusing. Why do you want to write a json object out to a file ending with the php extension? What are you looking for here? An edit of file with a json record will require I/O. – chsbellboy Mar 25 '16 at 03:17
  • Sorry, I was really noob when I asked this question. '.php' extension was random. The same thing can be done with a text file. – Shadowninjazx Jan 29 '17 at 04:04

1 Answers1

0

Going on just the first sentence where you say you want to parse a JSON file in Java, have you seen this post How to parse JSON in Java

Community
  • 1
  • 1
Paul MacGuiheen
  • 628
  • 5
  • 17