0

I am writing a program that will take a JSON file and extract data from it. I have found this tutorial and I did exactly the same thing but Netbeans is showing the error: Cannot find symbol

Netbeans is underlining the word parser in:

Object obj = parser.parse(new FileReader("/Users/test/NetBeansProjects/WORK/text.json"));

I downloaded and added the simple json library, but it didn't help solve the issue.

Here's the code:

import java.io.FileNotFoundException;
import java.io.FileReader;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.*; // I even imported the whole parser package.

public class Classy {
    public static void main(String[] args) {
        // NETBEANS UNDERLINES THE WORD PARSER ERROR: CANNOT FIND SYMBOL
        try{
            Object obj = parser.parse(new FileReader("/Users/test/NetBeansProjects/WORK/text.json"));
            JSONObject jsonObject = (JSONObject) obj;
            String name = (String) jsonObject.get("name");

        }
        catch (FileNotFoundException e){
            System.out.print(e.getMessage());
        }
    }
}
  • Two simple things that may help you. The first one is that you don't declare/instantiate the parse var. And you should also see this: https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean – Sebastian Aguerre Sep 19 '17 at 16:07
  • Did you see on video he created the JsonParser class to parser variable, I see you didn't do it – Tan Sep 19 '17 at 14:48

0 Answers0