List of usage examples for com.google.gson JsonParser JsonParser
@Deprecated
public JsonParser()
From source file:algorithmi.models.Schools.java
public Schools(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject schools = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(schools.entrySet()); //Revalidar TUDO, formatos, campos vazios, TUDO!! validateData();/*from w w w . ja va 2 s . c om*/ //TEM DE IR BUSCAR O ULTIMO ID E ACRESCENTAR UM this._id = 123; this.name = schools.get("name").getAsString(); this.institution = schools.get("institution").getAsInt(); }
From source file:algorithmi.models.TypeUser.java
License:Apache License
public TypeUser(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject UserType = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(UserType.entrySet()); /**/*from w w w . j a va 2 s . c o m*/ * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto UserType this.id_Type = UserType.getAsInt(); //ir buscar o max id da bd + 1 this.name = UserType.get("name").getAsString(); // }
From source file:algorithmi.models.User.java
License:Apache License
public User(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject user = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(user.entrySet()); /**/*from w w w. ja va 2 s . c o m*/ * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto User this._id = 123; //ir buscar o max id da bd + 1 this.name = user.get("name").getAsString(); // this.password = user.get("password").getAsString(); this.imgB64 = user.get("imgB64").getAsString(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); df.setLenient(false); Date dt; try { dt = df.parse(user.get("dateBirth").getAsString()); } catch (ParseException ex) { dt = new Date(); } this.dateBirth = dt; this.email = user.get("email").getAsString(); this.type = 3;//Definir o tipo de utilizador, como registo, dever ser do tipo aluno }
From source file:algorithmi.models.UserCourse.java
License:Apache License
public UserCourse(String data) { //Transforma a string recebida pelo pedido http para json JsonParser jsonParser = new JsonParser(); JsonObject UserCourse = (JsonObject) jsonParser.parse(data); //Exibe os dados, em formato json System.out.println(UserCourse.entrySet()); /**//from w w w.j av a 2 s . c o m * * Revalidar TUDO, formatos, campos vazios, TUDO!! * */ validateData(); //Associa os dados ao objecto UserCourse this.user = UserCourse.get("_id").getAsInt(); ; //ir buscar o max id da bd + 1 this.course = UserCourse.get("codCourse").getAsInt(); }
From source file:ambari.interaction.NodeController.java
public static ArrayList<ComponentInformation> getListOfNodes() throws Exception { String url = "http://127.0.0.1:8080/api/v1/clusters/mycluster/services/HDFS/components/DATANODE?fields=host_components/HostRoles/desired_admin_state,host_components/HostRoles/state"; String responseJson = HttpURLConnectionExample.sendGet(url); System.out.print(responseJson); JsonParser jsonParser = new JsonParser(); JsonElement jsonTree = jsonParser.parse(responseJson); ArrayList<ComponentInformation> listOfCompoents = new ArrayList<ComponentInformation>(); if (jsonTree.isJsonObject()) { JsonObject jsonObject = jsonTree.getAsJsonObject(); JsonElement hostComponents = jsonObject.get("host_components"); if (hostComponents.isJsonArray()) { JsonArray hostComponentsJsonArray = hostComponents.getAsJsonArray(); System.out.println("\nStart"); System.out.println(hostComponentsJsonArray); for (int i = 0; i < hostComponentsJsonArray.size(); i++) { JsonElement hostComponentsElem = hostComponentsJsonArray.get(i); if (hostComponentsElem.isJsonObject()) { JsonObject jsonObjectElem = hostComponentsElem.getAsJsonObject(); JsonElement hostRolesElem = jsonObjectElem.get("HostRoles"); if (hostRolesElem.isJsonObject()) { JsonObject hostRolesObjs = hostRolesElem.getAsJsonObject(); JsonElement componentNameElem = hostRolesObjs.get("component_name"); JsonElement hostNameElem = hostRolesObjs.get("host_name"); JsonElement stateElem = hostRolesObjs.get("state"); listOfCompoents.add(new ComponentInformation(componentNameElem.toString(), hostNameElem.toString(), stateElem.toString())); }/*from w w w . jav a 2s . co m*/ } } } } return listOfCompoents; }
From source file:angularBeans.util.AngularBeansUtil.java
License:Open Source License
public static JsonObject parse(String message) { JsonParser parser = new JsonParser(); JsonElement element = parser.parse(message); JsonObject jObj = element.getAsJsonObject(); return jObj;/*from w w w . j a v a2 s .co m*/ }
From source file:angularBeans.util.CommonUtils.java
License:LGPL
public static JsonElement parse(String message) { if (!message.startsWith("{")) { return new JsonPrimitive(message); }/*from w w w. ja v a2 s . c om*/ JsonParser parser = new JsonParser(); return parser.parse(message); }
From source file:aopdomotics.storage.food.FoodJsonDecoder.java
/** * Decode bill, using storage array(with prices) and bill json and return total price. * @param billJson//from w ww . java2 s . c om * @param magazinList * @return */ public static float decodeBill(String billJson, ArrayList<Food> magazinList) { JsonElement jelement = new JsonParser().parse(billJson); JsonObject json = jelement.getAsJsonObject(); JsonElement billElement = json.get("Bill"); System.out.println("Bill JSON " + billElement.toString()); Gson gson = new GsonBuilder().create(); FoodJsonDecoder billdecoder = gson.fromJson(billElement, FoodJsonDecoder.class); return billdecoder.billPrice(magazinList); }
From source file:aopdomotics.storage.food.FoodJsonDecoder.java
/** * Decode recipe using the three food items from json recipe. * @param recipeJson// www . ja v a 2s.c o m * @return */ public static Recipe decodeRecipe(String recipeJson) { Recipe recipe; Food[] component = new Food[3]; JsonElement jelement = new JsonParser().parse(recipeJson); JsonObject json = jelement.getAsJsonObject(); JsonElement recipeElement = json.get("Recipe"); System.out.println("Recipe JSON " + recipeElement.toString()); Gson gson = new GsonBuilder().create(); FoodJsonDecoder recipedecoder = gson.fromJson(recipeElement, FoodJsonDecoder.class); int i = 0; for (Food item : recipedecoder.foodList()) { if (item.quantity > 0) { component[i++] = item; } } recipe = new Recipe("eaten", component[0], component[1], component[2]); return recipe; }
From source file:aopdomotics.storage.food.FoodJsonDecoder.java
/** * Decode storage update json, return entire catalogue list * @param storageJson/*from www . jav a 2 s .co m*/ * @return */ public static ArrayList<Food> decodeStorage(String storageJson) { System.out.println("Storage Json : " + storageJson); JsonElement jelement = new JsonParser().parse(storageJson); JsonObject json = jelement.getAsJsonObject(); JsonElement storageElement = json.get("Storage"); System.out.println("Storage JSON " + storageElement.toString()); Gson gson = new GsonBuilder().create(); FoodJsonDecoder recipedecoder = gson.fromJson(storageElement, FoodJsonDecoder.class); return recipedecoder.foodList(); }