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());
}
}
}