Our Blog

Generate JSON data and Convert in PageBlockTable

Generate JSON data and Convert in PageBlockTable

In this post, I am going to share the information how to Generate JSON data and Convert in PageBlockTable and display the same in Visual Force page in tabular format.

 

JSON ( Java Script Object Notation )

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

The Apex JSON classes provide easy-to-use means of serializing/deserializing Apex objects into/from JSON content. This article explained the basics about handling JSON content in Apex. The code samples provided in the article demonstrated how different serialization and deserialization options could be implemented in Apex.

1. JSON has a smaller footprint than XML, which means it can be transmitted and parsed faster than XML.

2. JSON.serialize() is used to generate JSON.

3. It Simply have a key and value pair combination.

4. DataTypes supported by the JSON are “Number, String, Boolean, Array, Object and null”.

5. Key and value pair are separated by colon “:”

6. Object is enclosed between curly brackets “{” and “}”.

7. Array is enclosed using square bracket “[“, “]” separated by the comma.

Serialization and Deserialization

Apex Code :

public with sharing class jsongenerator {
  public   string jsondata{get;set;}
    public list<jsonvalue> jsonstring { get; set; }

public jsongenerator(){
    
    string soql ='select name,industry from account';
    List<Account> acct = Database.Query(soql);
    jsondata = JSON.serialize(acct);
    jsonstring = (List<jsonvalue>) System.JSON.deserialize(jsondata , List<jsonvalue>.class);
            
}
public class jsonvalue{

            public String name{get;set;}
            public String industry{get;set;}
         
}


}


Visualforce Page:

<apex:page controller="jsongenerator" showHeader="false"> 
{!jsondata}
<apex:pageblock >
<apex:pageblockTable value="{!jsonstring}" var="json">
<apex:column headerValue="Name" value="{!json.name}"/>
<apex:column headerValue="Industry" value="{!json.industry}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:page>

Json Data in Pageblock Table

 jsondata

Support

That’s all forGenerate JSON data and Convert in PageBlockTable  in Salesforce, still have any issue feel free to add a ticket and let us know your views to make the product better https://webkul.com/ticket/index.php

Read More: How to implement JSON in Apex Salesforce

Leave a Comment

Comments (0)

Please verify that you are not a robot.

Welcome back

Welcome back! Please enter your details

One or more fields have an error. Please check and try again.

Forgot Password?

Tell us about Your Company

How can we help you with your business?