How to read data from json File using java

2,398 views
Skip to first unread message

rashmeemayee mohapatra

unread,
Jan 30, 2014, 12:28:57 PM1/30/14
to seleniu...@googlegroups.com
i want to fetch data from json file using selenium webdriver java.Help me out

Krishnan Mahadevan

unread,
Jan 31, 2014, 8:51:35 PM1/31/14
to seleniu...@googlegroups.com
What does this have anything to do with Selenium/WebDriver ?
This is a Java question and so I suggest that you please :
1. Try googling for samples 
2. Post this query on Java forums  


On Thursday, January 30, 2014, rashmeemayee mohapatra <rashmeemaye...@gmail.com> wrote:
i want to fetch data from json file using selenium webdriver java.Help me out

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/123d4d33-3349-412b-a644-3fb85dcfcf66%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

Shawn Knight

unread,
Feb 2, 2014, 9:48:01 AM2/2/14
to seleniu...@googlegroups.com
And to add to Krishnan's comment, you should at least of tried to figure it out yourself before asking for help and then show the code you are with on. when you have a problem. Asking others to code something for you is not the answer.
And Yes, I do know how to fetch data from a json file.

Uday

unread,
Feb 3, 2014, 5:00:25 AM2/3/14
to seleniu...@googlegroups.com
I Agree with Krishna and Shawn - You can you Jackson java api.

rashmeemayee mohapatra

unread,
Feb 3, 2014, 12:43:18 PM2/3/14
to seleniu...@googlegroups.com
By using this we can fetch data .
i have written the code but finding some error,
package pagefactory;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;


public class JsonRead {

    public static void main(String[] args) {
        JSONParser parser = new JSONParser();
        try {
             
            Object obj = parser.parse(new FileReader("D:/java/workspace/MoonshotProject/JsonFile/test.json"));
     
            JSONObject jsonObject = (JSONObject) obj;
     
            String name = (String) jsonObject.get("name");
            System.out.println(name);
     
            long age = (Long) jsonObject.get("age");
            System.out.println(age);
     
            // loop array
            JSONArray msg = (JSONArray) jsonObject.get("messages");
            Iterator<String> iterator = msg.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
     
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();

        }
     
         }
     

}


    }

}


On Saturday, 1 February 2014 07:21:35 UTC+5:30, Krishnan wrote:
What does this have anything to do with Selenium/WebDriver ?
This is a Java question and so I suggest that you please :
1. Try googling for samples 
2. Post this query on Java forums  

On Thursday, January 30, 2014, rashmeemayee mohapatra <rashmeemaye...@gmail.com> wrote:
i want to fetch data from json file using selenium webdriver java.Help me out

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

Krishnan Mahadevan

unread,
Feb 4, 2014, 3:19:22 AM2/4/14
to Selenium Users
Rashmee
As stated before this question has got nothing to do with Selenium/Webdriver.

Please help keep this forum relevant by posting queries that are related to Selenium/WebDriver only [ Oh and btw, I am using WebDriver in my code doesnt mean that the question is related to WebDriver/Selenium]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7294f5ef-85a9-4b5c-b0b6-b918c03552fb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages