function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sekharasekhara 

System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set

Hi,

 

I've created below class and want to display records in Visual source page.

 

And my jSon :

{
   "data": [
      {
         "name": "dsvsd",
         "id": "5275838"
      },

 

 

 

public class JSON2Apex1{

    public class Data {
        public String name;
        public String id;
    }

    public class Paging {
        public String next;
    }

    public List<Data> data;
    public Paging paging;

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

neophyteneophyte

The JSON you posted is indeed malformed. Should have been like this:

{
   "data": [
      {
         "name": "dsvsd",
         "id": "5275838"
      }

    ]

}

 

sekharasekhara

Ya i have take same format which u have mentioned but same error is getting.

neophyteneophyte

The code given works perfectly fine for me, for the input I posted.

 

sekharasekhara

public class Facebook_Login_jSon {

    public class Data {
        public String name;
        public String id;
    }

    public class Paging {
        public String next;
    }

    public List<Data> data;
    public Paging paging;

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

 

here my doubt is how to take data from List<Data>

neophyteneophyte

I'm not sure what you mean here. You should process the list like any other list. Iterate through the list to get the records in it.

sekharasekhara

 [
      {
         "name": "dsvsd",
         "id": "5275838"
      }

    ]

 

It is taking as 

{
   "data": [
      {
         "name": "dsvsd",
         "id": "5275838"
      }

    ]

}

Up to my knowledge  this part is reason for getting error

{
   "data":

 

}