- Home
- Comunidad
- Programación
- A simple JSON example to access MyFxBook
Edit Your Comment
A simple JSON example to access MyFxBook
Apr 10, 2013 at 11:54
Miembro desde Apr 29, 2012
posts 4
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
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
Miembro desde May 15, 2013
posts 2
May 23, 2013 at 06:04
Miembro desde May 15, 2013
posts 2
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;
}
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;
}
Miembro desde May 15, 2013
posts 2
*El uso comercial y el spam no serán tolerados y pueden resultar en el cierre de la cuenta.
Consejo: Al publicar una imagen o una URL de YouTube, ésta se integrará automáticamente en su mensaje!
Consejo: Escriba el signo @ para completar automáticamente un nombre de usuario que participa en esta discusión.