0

I'm not able to get rows list....it is coming null from below code.

   public class ParsingTest1 
    {
     public ParsingTest1()
     {
       String jsstring = '{"totalsForAllResults": {"users": "2"}, "rows": 
        [["San Francisco","358","375"],["San Jose","358","375"],["Mid 
        Peninsula","358","375"],["Greater Bay","358","375"],["Los 
        Angeles","358","375"]]}';
       Test1Wrapper tw = new Test1Wrapper();
       tw = 
       (Test1Wrapper)System.JSON.deserialize(jsstring,Test1Wrapper.class);
       system.debug('Result : '+tw);
     }

   public class Test1Wrapper
   {
     public map<string,string> totalsForAllResults { get; set;}
     public list<rows> r1 { get; set; }
   }

   public class rows
   {
      public string n1 { get; set; }
      public string s1 { get; set; }
      public string s2 { get; set; }
   }   
 }
0
1

Put the JSON through http://json2apex.herokuapp.com to get the appropriate classes generated:

//
// Generated by JSON2Apex http://json2apex.herokuapp.com/
//

public class Root {

    public TotalsForAllResults totalsForAllResults;
    public List<List<String>> rows;

    public class TotalsForAllResults {
        public String users;
    }


    public static Root parse(String json) {
        return (Root) System.JSON.deserialize(json, Root);
    }
}

Your JSON includes an array of arrays. Worth reading http://json.org/ to get a clearer view of how JSON represents data.

1
  • Now I'm getting correct values...Thanks for the quick response. Nov 1 '18 at 10:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.