Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:02:09+00:00 2026-06-01T12:02:09+00:00

I want to parse this Json code : [{id:7,key:integrationContinue:integrationContinue,name:life Portlet,scope:PRJ,qualifier:TRK,date:2012-03-26T10:10:22+0100,lname:life Portlet,lang:java,version:1.0-SNAPSHOT,description:,msr:[{key:ncloc,val:897.0,frmt_val:897},{key:coverage,val:0.6,frmt_val:0,6%}]}] I created two

  • 0

I want to parse this Json code :

[{"id":7,"key":"integrationContinue:integrationContinue","name":"life Portlet","scope":"PRJ","qualifier":"TRK","date":"2012-03-26T10:10:22+0100","lname":"life Portlet","lang":"java","version":"1.0-SNAPSHOT","description":"","msr":[{"key":"ncloc","val":897.0,"frmt_val":"897"},{"key":"coverage","val":0.6,"frmt_val":"0,6%"}]}]

I created two classes :

 public class Ressources {

  private String id;
    private String key;
    private String name;
    private String lname;
    private String scope;
    private String qualifier;
    private String lang;
    private String version;
    private String date;
    private List<Mesures> msr;


    public Ressources() {

    }

    public Ressources(String id, String key, String name, String lname,
            String scope, String qualifier, String lang, String version,
            String date, List<Mesures> msr) {
        super();
        this.id = id;
        this.key = key;
        this.name = name;
        this.lname = lname;
        this.scope = scope;
        this.qualifier = qualifier;
        this.lang = lang;
        this.version = version;
        this.date = date;
        this.msr = msr;
    }
 @Override
 public String toString() {return "Ressources : \n id=" + id  + ",\n key=" + key + ",\n name=" + name + ",\n lname=" + lname + ",\n scope=" + scope + ",\n qualifier=" + qualifier + ",\n lang=" + lang + ",\n version=" + version + ",\n date=" + date;

}

 public class Ressources {

  private String id;
    private String key;
    private String name;
    private String lname;
    private String scope;
    private String qualifier;
    private String lang;
    private String version;
    private String date;
    private List<Mesures> msr;


    public Ressources() {

    }

    public Ressources(String id, String key, String name, String lname,
            String scope, String qualifier, String lang, String version,
            String date, List<Mesures> msr) {
        super();
        this.id = id;
        this.key = key;
        this.name = name;
        this.lname = lname;
        this.scope = scope;
        this.qualifier = qualifier;
        this.lang = lang;
        this.version = version;
        this.date = date;
        this.msr = msr;
    }
 @Override
 public String toString() {return "Ressources : \n id=" + id  + ",\n key=" + key + ",\n name=" + name + ",\n lname=" + lname + ",\n scope=" + scope + ",\n qualifier=" + qualifier + ",\n lang=" + lang + ",\n version=" + version + ",\n date=" + date;}

(with getters and setters)

public class Mesures {


private String key;
private float val;
private String frmt_val;

public Mesures(){}
public Mesures(String akey, float aval,String afrmt_val ){
    key=akey;
    val=aval;
    frmt_val=afrmt_val;

}

 @Override
 public String toString() {return " \n key=" + key  + ",\n val=" + val + ",\n frmt_val=" + frmt_val;
}

then I created two functions :

 public List<Ressources> parseGson_Ressources(String jsonToParse) {

        JsonElement jsonElement = new JsonParser().parse(jsonToParse);
        JsonArray array = jsonElement.getAsJsonArray();

        @SuppressWarnings("rawtypes")
        Iterator iterator = array.iterator();
        List<Ressources> ressources = new ArrayList<Ressources>();

        while (iterator.hasNext()) {
            JsonElement jsontmp = (JsonElement) iterator.next();
            Gson gson = new Gson();
            Ressources ressource1 = gson.fromJson(jsontmp, Ressources.class);        
            ressources.add(ressource1);

        }

        return ressources;
    }

 public List<Mesures> parseGson_Mesures(String jsonToParse) {

        JsonElement jsonElement = new JsonParser().parse(jsonToParse);
        JsonArray array = jsonElement.getAsJsonArray();

        @SuppressWarnings("rawtypes")
        Iterator iterator = array.iterator();
        List<Mesures> mesures = new ArrayList<Mesures>();

        while (iterator.hasNext()) {
            JsonElement jsontmp = (JsonElement) iterator.next();
            Gson gson = new Gson();
            Mesures mesure = gson.fromJson(jsontmp, Mesures.class);
            mesures.add(mesure);
        }   
        return mesures;
    }

then I wrote this code to get the result:

 String xxx = RequestSonar(); //wich return the Json result

     List<Ressources> listRessources = new ArrayList<Ressources>();
     listRessources = rs.parseGson_Ressources(xxx);
     Iterator<Ressources> iterator;
     iterator = listRessources.iterator();

     while (iterator.hasNext()) {

         Ressources ressource = iterator.next();
         System.out.println(ressource.toString());
     }
     List<Mesures> listMesures = new ArrayList<Mesures>();
     Iterator<Mesures> iterator2;
     listMesures = rs.parseGson_Mesures(xxx);
     iterator2 = listMesures.iterator();

     while (iterator2.hasNext()) {

        Mesures mesure = iterator2.next();
        System.out.println(mesure.toString());
    }

After executing I get this result:

Ressources : 
id=7,
key=integrationContinue:integrationContinue,
name=life Portlet,
lname=life Portlet,
scope=PRJ,
qualifier=TRK,
lang=java,
version=1.0-SNAPSHOT,
date=2012-03-26T10:10:22+0100

key=integrationContinue:integrationContinue,
val=0.0,
frmt_val=null

How can I fix this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:02:11+00:00Added an answer on June 1, 2026 at 12:02 pm
    i think this will help you,
    
    create two classes with getter setter methods
    
    public class Ressources {
    
        private String id;
        private String key;
        private String name;
        private String lname;
        private String scope;
        private String qualifier;
        private String lang;
        private String version;
        private String date;
        private List<Mesures> msr;
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public String getKey() {
            return key;
        }
    
        public void setKey(String key) {
            this.key = key;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getLname() {
            return lname;
        }
    
        public void setLname(String lname) {
            this.lname = lname;
        }
    
        public String getScope() {
            return scope;
        }
    
        public void setScope(String scope) {
            this.scope = scope;
        }
    
        public String getQualifier() {
            return qualifier;
        }
    
        public void setQualifier(String qualifier) {
            this.qualifier = qualifier;
        }
    
        public String getLang() {
            return lang;
        }
    
        public void setLang(String lang) {
            this.lang = lang;
        }
    
        public String getVersion() {
            return version;
        }
    
        public void setVersion(String version) {
            this.version = version;
        }
    
        public String getDate() {
            return date;
        }
    
        public void setDate(String date) {
            this.date = date;
        }
    
        public List<Mesures> getMsr() {
            return msr;
        }
    
        public void setMsr(List<Mesures> msr) {
            this.msr = msr;
        }
    
    }
    
    public class Mesures {
    
        private String key;
        private float val;
        private String frmt_val;
    
        public String getKey() {
            return key;
        }
    
        public void setKey(String key) {
            this.key = key;
        }
    
        public float getVal() {
            return val;
        }
    
        public void setVal(float val) {
            this.val = val;
        }
    
        public String getFrmt_val() {
            return frmt_val;
        }
    
        public void setFrmt_val(String frmt_val) {
            this.frmt_val = frmt_val;
        }
    
    }
    
    then use this to Parse your JSON
    
    String jsonl = "[{'id':7,'key':'integrationContinue:integrationContinue','name':'life Portlet','scope':'PRJ','qualifier':'TRK','date':'2012-03-26T10:10:22+0100','lname':'life Portlet','lang':'java','version':'1.0-SNAPSHOT','description':'','msr':[{'key':'ncloc','val':897.0,'frmt_val':'897'},{'key':'coverage','val':0.6,'frmt_val':'0,6%'}]}]";
    
    Gson gson = new Gson();
    Type collectionType = new TypeToken<List<Ressources>>() {
            }.getType();
    List<Ressources> ressourcesList = gson.fromJson(jsonl, collectionType);
    
    Ressources ressources = ressourcesList.get(0);
    System.out.println("id :" + ressources.getId());
    System.out.println("key :" + ressources.getKey());
    System.out.println("name :" + ressources.getName());
    System.out.println("scope :" + ressources.getScope());
    System.out.println("qualifier :" + ressources.getQualifier());
    System.out.println("date :" + ressources.getDate());
    System.out.println("lname :" + ressources.getLname());
    System.out.println("lang :" + ressources.getLang());
    System.out.println("version :" + ressources.getVersion());
    System.out.println("Mrs :");
    
    List<Mesures> mrsList = ressources.getMsr();
    for (int i = 0; i < mrsList.size(); i++) {
    System.out.println("key :" + mrsList.get(i).getKey());
    System.out.println("val :" + mrsList.get(i).getVal());
    System.out.println("frmt_val :" + mrsList.get(i).getFrmt_val());
    }
    
    
    output:
    
    id :7
    key :integrationContinue:integrationContinue
    name :life Portlet
    scope :PRJ
    qualifier :TRK
    date :2012-03-26T10:10:22+0100
    lname :life Portlet
    lang :java
    version :1.0-SNAPSHOT
    Mrs :
    key :ncloc
    val :897.0
    frmt_val :897
    key :coverage
    val :0.6
    frmt_val :0,6%
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse this CSS Selector (and others of a similar form): div.class1#myid.class2[key=value]
I want to display place details from this json: I have problem with parse
I want to parse the JSON [ { food: [ { name: pasta, price:
This is JSON returned var errorsObject = JSON.parse('{ fieldErrors: {name:[You must enter your name1],name:[You
I want to parse this JSON YouTube recently featured . This is how I
I want to parse this piece of JSON in C# with JSON.NET, but I
I want to parse the json data shown in this link in AS3 to
I am working in android. I want to parse my json data. This is
this the JSON data that i want to parse in my application: { viewdeal:[
I'm receiving an xml response and I now want to parse this. Currently what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.