How to get Json data - java

I have a json array like this
{
"success":"true",
"crops": {
"Brinjal":[---varieties of brinjal---],
"apple":[---varieties of apple---],
.................
.................
}
}
So i have got the complete crops using.....
JSONObject jsonObject;
jsonObject.getString("crops")
but i actually need to create two arrays like
String[] crops = {"Brinjal","apple"};
String[] varities = {"---Brinjal Varities---","---apple varities---"};
how can I generate these two arrays
if i generate "crops" then i can generate other array....
so how can i generate the "crops"...

You should do:
JSONObject obj = new JSONObject(jsonStringResp);
JSONObject cropsObj = obj.getJSONObject("crops");
JSONArray arr1 = subObject.getJSONArray("Brinjal");
Then you iterate over the JSON array and create the String array.
Hope it helps you.

public static void main(String[]args){
String joson = "{\n" +
" \"success\":\"true\",\n" +
" \"crops\": {\n" +
" \"Brinjal\":[---varieties of brinjal---],\n" +
" \"apple\":[---varieties of apple---],\n" +
" .................\n" +
" .................\n" +
" }\n" +
"}";
List<Object> apple = new ArrayList<Object>();
List<Object> Brinjal = new ArrayList<Object>();
apple.add("---varieties of apple---");
Brinjal.add("---varieties of brinjal---");
Map<String,Object> mapF = new HashMap<String,Object>();
Map<String,Object> mapS = new HashMap<String,Object>();
mapS.put("Brinjal", Brinjal);
mapS.put("apple", apple);
mapF.put("success", "true");
mapF.put("crops",mapS );
JSONObject obj = new JSONObject().fromObject(mapF);
System.out.println(obj);
JSONObject objF = obj.getJSONObject("crops");
String[] ListF = {};
String str = objF.keySet().toString();
String strF = str.substring(1, str.length()-1);
ListF = strF.split(", ");
List<Object> lsitF = new ArrayList<Object>();
for(int i = 0;i<ListF.length;i++){
lsitF.add(objF.get(ListF[i]));[enter image description here][1]
}
System.out.println(str);
System.out.println(lsitF.toString());
}
Hope it helps you.

Try this:
String joson = "{\n" +
" \"success\":\"true\",\n" +
" \"crops\": {\n" +
" \"Brinjal\":[---varieties of brinjal---],\n" +
" \"apple\":[---varieties of apple---],\n" +
" .................\n" +
" .................\n" +
" }\n" +
"}";
List<String> whereCrops = new ArrayList<String>();
List<String> whereVarities = new ArrayList<String>();
String[] crops;
String[] varities;
ArrayList<String> contentKey = new ArrayList<String>();
try {
JSONObject myObject = new JSONObject(joson);
JSONObject jsonCrops = myObject.getJSONObject("crops");
Iterator<String> iter = jsonCrops.keys();
while (iter.hasNext()) {
String key = iter.next();
whereCrops.add(key);
Log.e("inningskey", key);
try {
JSONArray array = jsonCrops.getJSONArray(key);
whereVarities.add(array.toString());
} catch (JSONException e) {
// Something went wrong!
}
}
// here ! you need convert whereCrops to crops
} catch (JSONException e) {
e.printStackTrace();
}
}

Related

No values from JSON

I'd like to display values from my JSON just for testing purposes, but I've received literally nothing. Where can be an issue? The link in Utils is correctly for sure, I've runned it on my browser, and everything was good.
Here's the code
Utils class
public class WeatherUtils {
public WeatherUtils(){}
public static ArrayList<Weather> getHourlyData (double minTemp, double maxTemp, double currentTemp, double airPressure){
ArrayList<Weather> weatherList = new ArrayList<>();
try {
JSONObject reader = new JSONObject("https://api.openweathermap.org/data/2.5/forecast?q=London,us&units=metric&appid=ID...");
JSONArray array = reader.getJSONArray("list");
for (int i = 0; i<array.length(); i++){
JSONObject secondReader = array.getJSONObject(i);
JSONObject dataObject = secondReader.getJSONObject("main");
for (int j = 0; j<dataObject.length(); j++){
currentTemp = dataObject.getDouble("temp");
minTemp = dataObject.getDouble("temp_min");
maxTemp = dataObject.getDouble("temp_max");
airPressure = dataObject.getDouble("pressure");
}
weatherList.add(new Weather(currentTemp,minTemp,maxTemp,airPressure));
}
} catch (JSONException e) {
e.printStackTrace();
}
return weatherList;
}
}
MainActivity
Double a,b,c,d;
a = 0.0;
b = 0.0;
c = 0.0;
d = 0.0;
ArrayList<Weather> weathers = WeatherUtils.getHourlyData(a,b,c,d);
System.out.println(weathers);
JSON structure
{
"cod": "200",
"message": 0.0074,
"cnt": 40,
"list": [
{
"dt": 1559131200,
"main": {
"temp": 22.1,
"temp_min": 21.32,
"temp_max": 22.1,
"pressure": 1012.31,
"sea_level": 1012.31,
"grnd_level": 976.84,
"humidity": 92,
"temp_kf": 0.78
},
"weather": [
{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}
],
"clouds": {
"all": 89
},
"wind": {
"speed": 3.08,
"deg": 213.025
},
"rain": {
"3h": 0.875
},
"sys": {
"pod": "d"
},
"dt_txt": "2019-05-29 12:00:00"
},
{
Of course, there are more data. I've posted one "block"
How I may fix that?
Well, given that you just want to "test" the json parsing, you have few options but let's go with a simple one. But first, I would say to extract the parser and put it in its own class/method so it becomes easier to test, something like this:
public class WeatherUtils {
public WeatherUtils(){}
public static ArrayList<Weather> getHourlyData (double minTemp, double maxTemp, double currentTemp, double airPressure){
final ArrayList<Weather> weatherList = new ArrayList<>();
try {
final JSONObject response = httpCall();
weatherList = mapWeatherResponse(response);
} catch (JSONException e) {
e.printStackTrace();
}
return weatherList;
}
public static List<Weather> mapWeatherResponse(JSONObject reader){
final ArrayList<Weather> weatherList = new ArrayList<>();
JSONArray array = reader.getJSONArray("list");
for (int i = 0; i<array.length(); i++){
JSONObject secondReader = array.getJSONObject(i);
JSONObject dataObject = secondReader.getJSONObject("main");
for (int j = 0; j<dataObject.length(); j++){
currentTemp = dataObject.getDouble("temp");
minTemp = dataObject.getDouble("temp_min");
maxTemp = dataObject.getDouble("temp_max");
airPressure = dataObject.getDouble("pressure");
}
weatherList.add(new Weather(currentTemp,minTemp,maxTemp,airPressure));
}
}
}
Test the response parser with a junit test:
You can create a junit test like this:
public class WeatherUtilsTest {
#Test
public void parserResponseTEst() {
final List<String> expectedResponse = new ArrayList<>();
//fill the expectedResponse with the correspondent values
final String json = "{\n" +
" \"cod\": \"200\",\n" +
" \"message\": 0.0074,\n" +
" \"cnt\": 40,\n" +
" \"list\": [\n" +
" {\n" +
" \"dt\": 1559131200,\n" +
" \"main\": {\n" +
" \"temp\": 22.1,\n" +
" \"temp_min\": 21.32,\n" +
" \"temp_max\": 22.1,\n" +
" \"pressure\": 1012.31,\n" +
" \"sea_level\": 1012.31,\n" +
" \"grnd_level\": 976.84,\n" +
" \"humidity\": 92,\n" +
" \"temp_kf\": 0.78\n" +
" },\n" +
" \"weather\": [\n" +
" {\n" +
" \"id\": 500,\n" +
" \"main\": \"Rain\",\n" +
" \"description\": \"light rain\",\n" +
" \"icon\": \"10d\"\n" +
" }\n" +
" ],\n" +
" \"clouds\": {\n" +
" \"all\": 89\n" +
" },\n" +
" \"wind\": {\n" +
" \"speed\": 3.08,\n" +
" \"deg\": 213.025\n" +
" },\n" +
" \"rain\": {\n" +
" \"3h\": 0.875\n" +
" }\n" +
" }]\n" +
" }";
final List<String> response = WeatherUtils.mapWeatherResponse(new JSONObject(json));
assertEquals(expectedResponse, response);
}
}
There is nothing wrong with the JSONObject parser you are doing. You mentioned the link you are using in Utils is correct, do you get a proper response when you test it in your browser, postman, insomnia?
OBS JSONObject reader = new JSONObject("https://api..."); does not fetch anything, what you are doing there is creating a JSONObject from the given String, i.e. "https://....". To fetch the data you need to implement some http client. Here is an example https://stackoverflow.com/a/4457526/761668
You're not getting the response from the server, you're trying to initialize a JSONObject with the URL.
To retrieve it you should replace this line:
JSONObject reader = new JSONObject("https://api.openweathermap.org/data/2.5/forecast?q=London,us&units=metric&appid=ID...");
with this code:
HttpURLConnection conn = null;
String data = null;
try {
conn = (HttpURLConnection) new URL("https://api.openweathermap.org/data/2.5/forecast?q=London,us&units=metric&appid=ID...").openConnection();
conn.setRequestMethod("GET");
conn.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
data = sb.toString();
} catch (Exception e) {
// do something
} finally {
if (conn != null) {
try {
conn.disconnect();
} catch (Exception ex) {
// do something
}
}
}
JSONObject reader = new JSONObject(data);
This code will retrieve the JSON object from the endpoint and convert it to a String object. Then you can create a JSONObject with it.

How to get Jsonobject from list in java?

I have two jsonobject which is in list. If I make new jsonobject and trying to get list in that it is giving me null.
Code is here below-
private int isExisting(String pid, List profile, String size) throws JSONException {
for (int i = 0; i < profile.size(); i++) {
JSONObject obj = new JSONObject(profile.get(i));
log.info("--------------" + obj.toString()); //it is giving me an empty object but list contains two objects {"size":"M","id":11} and {"size":8,"id":19}
}
}
I tried this it worked
private void isExisting(String pid, List profile, String size) throws JSONException {
for (int i = 0; i < profile.size(); i++) {
if(profile.get(i)!=null) {
JSONObject obj = new JSONObject(profile.get(i).toString());
System.out.print("keys----------" + obj.toString());
}
}
}
public void processList() {
try {
JSONObject objA= new JSONObject("{\n" +
" \"size\": \"M\",\n" +
" \"id\": 11\n" +
" }");
JSONObject objB=new JSONObject("{\n" +
" \"size\": 8,\n" +
" \"id\": 19\n" +
" }");
List<JSONObject> list=new ArrayList<>();
list.add(objA);
list.add(objB);
isExisting("",list,"");
} catch (JSONException e) {
e.printStackTrace();
}
}
I have tried this simple logic and it is working fine-
private int isExisting(String pid, List profile, String size) throws JSONException {
for (int i = 0; i < profile.size(); i++) {
JSONObject obj = (JSONObject) profile.get(i);
log.info("--------------" + obj.toString());
}
}

Parsing JSON string in Java android

I want to extract elements (state,county ) from this JSON string :
I am trying to parse a JSON string in java to have the individual value printed separately. But while making the program run I get nothing.
"place": [
{
"address": {
"country_code": "fr",
"country": "France",
"state": "Normandie",
"county": "Calvados"
},
"icon": "http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png",
"importance": 0.74963706049207,
"type": "administrative",
"class": "boundary",
"display_name": "Calvados, Normandie, France",
"lon": "-0.24139500722798",
"lat": "49.09076485",
"boundingbox": [
"48.7516623",
"49.4298653",
"-1.1597713",
"0.4466332"
],
"osm_id": "7453",
"osm_type": "relation",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
"place_id": "158910871"
}
]
any help would be appreciated. thanks.
these is my android code :
JSONObject objectPremium = new JSONObject(String.valueOf(result));
String premium = objectPremium.getString("premium");
JSONArray jArray1 = objectPremium.getJSONArray("premium");
for(int i = 0; i < jArray1.length(); i++)
{
JSONObject object3 = jArray1.getJSONObject(i);
adresse = object3.getJSONObject("place").getJSONObject("address").getString("state");
Log.e("mylog",adresse);
}
In your JSON string, "place" is a JSONArray and its containing another JSONObject. Get "place" value as below:
// Place
JSONArray place = jsonObj.getJSONArray("place");
Get "address" value as below:
// Address
JSONObject address = place.getJSONObject(0).getJSONObject("address");
Get "countryCode", "country", "state" and "county" value as below:
String countryCode = address.getString("country_code");
String country = address.getString("country");
String state = address.getString("state");
String county = address.getString("county");
Here is the fully working code. Try this:
public void parseJson() {
// Your JOSON string
String jsonStr = "{\"place\": [\n" +
" {\n" +
" \"address\": {\n" +
" \"country_code\": \"fr\",\n" +
" \"country\": \"France\",\n" +
" \"state\": \"Normandie\",\n" +
" \"county\": \"Calvados\"\n" +
" },\n" +
" \"icon\": \"http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png\",\n" +
" \"importance\": 0.74963706049207,\n" +
" \"type\": \"administrative\",\n" +
" \"class\": \"boundary\",\n" +
" \"display_name\": \"Calvados, Normandie, France\",\n" +
" \"lon\": \"-0.24139500722798\",\n" +
" \"lat\": \"49.09076485\",\n" +
" \"boundingbox\": [\n" +
" \"48.7516623\",\n" +
" \"49.4298653\",\n" +
" \"-1.1597713\",\n" +
" \"0.4466332\"\n" +
" ],\n" +
" \"osm_id\": \"7453\",\n" +
" \"osm_type\": \"relation\",\n" +
" \"licence\": \"Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright\",\n" +
" \"place_id\": \"158910871\"\n" +
" }\n" +
" ]}";
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Place
JSONArray place = jsonObj.getJSONArray("place");
// Address
JSONObject address = place.getJSONObject(0).getJSONObject("address");
String countryCode = address.getString("country_code");
String country = address.getString("country");
String state = address.getString("state");
String county = address.getString("county");
Log.d("SUCCESS", "State: " + state + " Country: " + country + " County: " + county);
} catch (final JSONException e) {
Log.e("FAILED", "Json parsing error: " + e.getMessage());
}
}
}
Hope this will help~
The first thing you need is to make sure you are receiving this string or not. I am assuming you are trying to fetch it from some URL.
To fetch the JSON you can use the following code snippet.
private void getJSON(final String urlWebService) {
class GetJSON extends AsyncTask<Void, Void, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
}
#Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json + "\n");
}
return sb.toString().trim();
} catch (Exception e) {
return null;
}
}
}
GetJSON getJSON = new GetJSON();
getJSON.execute();
}
You need to pass your URL to this function. And if calling this method is displaying the JSON data that you are expecting then the first part is done. You have the JSON string in onPostExecute() method.
Now you can easily parse this string if it contains a valid JSON data. But the JSON that you shown in your question does not seems a valid JSON. I guess it is only part of a big JSON file. So if you need the exact code to parse your JSON post the full JSON.
Pat parsing is very easy. If the json you have is an object create an instance of JSONObject if it is an array create an instance of JSONObject.
Then you can easily get the keys if it is an object. Or you can traverse through items if it is an array.
For more details you can check this JSON Parsing in Android post.
Change for this:
JSONObject objectPremium = new JSONObject(String.valueOf(result));
String premium = objectPremium.getString("premium");
JSONArray jArray1 = objectPremium.getJSONArray("premium");
for(int i = 0; i < jArray1.length(); i++)
{
JSONObject object3 = jArray1.getJSONObject(i);
JSONArray placeArray = object3.getJSONArray("place")
JSONObject addressObject = placeArray.getJSONObject("address");
adress = addressObject.getString("state");
Log.e("mylog",adresse);
}
If your initial part of the JSON Parsing code is correct, then this should work!
JSONArray jArray = new JSONArray(result);
JSONObject objectPremium = jArray.get(0);
JSONObject json = jsonObject.getJSONObject("address");
String state = json.getString("state");
String country = json.getString("country");
Check this code,
this is how you parse and store in a list
String jsonStr = //your json string
HashMap<String, String> addressList= new HashMap<>();
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray address = jsonObj.getJSONArray("address"); // for the address
// looping through All that
for (int i = 0; i < address.length(); i++) {
JSONObject c = address.getJSONObject(i);
String country_code= c.getString("country_code");
String country= c.getString("country");
String state= c.getString("state");
String county = c.getString("county");
// adding each child node to HashMap key => value
address.put("country_code", country_code);
address.put("country", country);
address.put("state", state);
address.put("county", county);
// adding address to address list
addressList.add(address);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
}

How do i parse large json files with json.simple?

I am new to JSON and I am learning using the json.simple library. I try to parse a large json file, but all i get is “OutOfMemoryError: GC overhead limit exceeded”. How can i parse large json files?
this is my code:
private static void fillPublications() throws FileNotFoundException, IOException, SQLException {
JSONParser parser = new JSONParser();
try {
String username = System.getProperty("user.name");
String filename = "Datenbank";
Object jsonData = parser.parse(new FileReader("C:\\Users\\" + username + "\\Desktop\\JSON\\" + filename + ".json"));
ArrayList<String[]> list = new ArrayList<String[]>();
JSONArray jsonArray = (JSONArray) jsonData;
Iterator iterator = jsonArray.iterator();
String name = "";
Integer count = 0;
while (iterator.hasNext()) {
String[] database = new String[11];
JSONObject obj = (JSONObject) iterator.next();
if(obj.containsKey("title")){
database[0] = (String) obj.get("title");
}
if(obj.containsKey("year")){
database[1] = obj.get("year").toString();
}
if(obj.containsKey("keywords")){
JSONArray keywords = (JSONArray) obj.get("keywords");
Iterator<String> i = keywords.iterator();
String key = "";
while (i.hasNext()) {
key = key + i.next() + "#";
}
if(key.length() > 0 && key.charAt(key.length()-1)=='#'){
key = key.substring(0, key.length()-1);
}
database[2] = key;
}
if(obj.containsKey("pages")){
database[3] = (String) obj.get("pages");
}
if(obj.containsKey("volume")){
database[4] = (String) obj.get("volume");
}
if(obj.containsKey("abstract")){
database[5] = (String) obj.get("abstract");
}
if(obj.containsKey("identifiers")){
JSONObject identifiers = (JSONObject) obj.get("identifiers");
database[6] = (String) identifiers.get("doi");
}
if(obj.containsKey("type")){
database[8] = (String) obj.get("type");
}
if(obj.containsKey("authors")){
JSONArray arr = (JSONArray) obj.get("authors");
Iterator i = arr.iterator();
while(i.hasNext()){
JSONObject authorObject = (JSONObject) i.next();
name = name + (String) authorObject.get("first_name") + " " + (String) authorObject.get("last_name") + "#";
}
if(name.length() > 0 && name.charAt(name.length()-1)=='#'){
name = name.substring(0, name.length()-1);
}
database[10] = name;
}
list.add(database);
}
System.out.println(Arrays.toString(list.get(0)));
}catch (Exception e) {
System.err.println(e);
}
}
and this is what i get:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.lang.StringBuffer.toString(StringBuffer.java:673)
at org.json.simple.parser.Yylex.yylex(Yylex.java:598)
at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
at JSONExtraction.fillAuthors(JSONExtraction.java:39)
at JSONExtraction.main(JSONExtraction.java:23)
C:\Users\b\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1

Modifying a collection property using the Rally Rest API in Java

I'm trying to modify the TestSets property of a TestCase.
JsonArray newTestSets = new JsonArray();
... add values as needed ( in the simplest case I'm clearing the property )
JsonObject updates = new JsonObject();
updates.add("TestSets", newTestSets);
I create the updateRequest like I do for all other updates
UpdateRequest updateRequest = new UpdateRequest(ref, updates)
I don't get any error but nothing has changed. The TestCase is still in several TestSets
What am I missing?
I verified that it works to update TestSets collection on a TestCase. See this github repo.
public class UpdateTestSetsOnTestCase {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String workspaceRef = "/workspace/12352608129";
String applicationName = "RestExample_updateTestSetsOnTC";
RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
try {
String setID = "TS24";
String testid = "TC3";
QueryRequest tsRequest = new QueryRequest("TestSet");
tsRequest.setWorkspace(workspaceRef);
tsRequest.setQueryFilter(new QueryFilter("FormattedID", "=", setID));
QueryResponse tsQueryResponse = restApi.query(tsRequest);
if(tsQueryResponse.getTotalResultCount() == 0){
System.out.println("Cannot find tag: " + setID);
return;
}
JsonObject tsJsonObject = tsQueryResponse.getResults().get(0).getAsJsonObject();
String tsRef = tsJsonObject.get("_ref").getAsString();
System.out.println(tsRef);
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "TestSets"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", testid));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);;
if (testCaseQueryResponse.getTotalResultCount() == 0) {
System.out.println("Cannot find test case : " + testid);
return;
}
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseJsonObject.get("_ref").getAsString();
System.out.println(testCaseRef);
int numberOfTestSets = testCaseJsonObject.getAsJsonObject("TestSets").get("Count").getAsInt();
System.out.println(numberOfTestSets + " testset(s) on " + testid);
QueryRequest testsetCollectionRequest = new QueryRequest(testCaseJsonObject.getAsJsonObject("TestSets"));
testsetCollectionRequest.setFetch(new Fetch("FormattedID"));
JsonArray testsets = restApi.query(testsetCollectionRequest).getResults();
for (int j=0;j<numberOfTestSets;j++){
System.out.println("FormattedID: " + testsets.get(j).getAsJsonObject().get("FormattedID"));
}
testsets.add(tsJsonObject);
JsonObject testCaseUpdate = new JsonObject();
testCaseUpdate.add("TestSets", testsets);
UpdateRequest updateTestCaseRequest = new UpdateRequest(testCaseRef,testCaseUpdate);
UpdateResponse updateTestCaseResponse = restApi.update(updateTestCaseRequest);
if (updateTestCaseResponse.wasSuccessful()) {
QueryRequest testsetCollectionRequest2 = new QueryRequest(testCaseJsonObject.getAsJsonObject("TestSets"));
testsetCollectionRequest2.setFetch(new Fetch("FormattedID"));
JsonArray testsetsAfterUpdate = restApi.query(testsetCollectionRequest2).getResults();
int numberOfTestSetsAfterUpdate = restApi.query(testsetCollectionRequest2).getResults().size();
System.out.println("Successfully updated : " + testid + " TestSets after update: " + numberOfTestSetsAfterUpdate);
for (int j=0;j<numberOfTestSetsAfterUpdate;j++){
System.out.println("FormattedID: " + testsetsAfterUpdate.get(j).getAsJsonObject().get("FormattedID"));
}
}
} finally {
restApi.close();
}
}
}

Categories

Resources