A simple JSON example to access MyFxBook

Apr 10, 2013 at 11:54
920 Просмотры
2 Replies
Участник с Apr 29, 2012   4 комментариев
Apr 10, 2013 at 11:54
Hi,

would somebody have a small JSON based example to share that would help in getting started with using JSON to retrieve and display data from MyFxBook?

Just a very basic one to help understand the structure of the way it's done, so e.g. have a login, retrieve something from MyFxBook and then writing that to the browser/display.

That would great!

Thanks,
M
Участник с May 15, 2013   2 комментариев
May 23, 2013 at 06:04
Sure, here you go:

This is in Java.

public Session getData(String username, String password) throws MalformedURLException, IOException{
Gson json = null;
URL url = null;
Session session = null;
                String myfxbook= 'https://www.myfxbook.com/api/login.json?';


URL url = new URL(myfxbook + 'email=' + username + '&password=' + password);

InputStream is = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));

json = new GsonBuilder().setPrettyPrinting().create();

session = json.fromJson(reader, Session.class); //puts the json into a bean



return session;
}
Участник с May 15, 2013   2 комментариев
May 23, 2013 at 06:04
Hmm, the forum ate the code...
You must be connected to Myfxbook in order to leave a comment
*Коммерческое использование и спам не допускаются и могут привести к аннулированию аккаунта.
Совет: Размещенные изображения или ссылки на Youtube автоматически вставляются в ваше сообщение!
Совет: введите знак @ для автоматического заполнения имени пользователя, участвующего в этом обсуждении.