You need to sign in to do that
Don't have an account?

Generating the simple json using the json generator
Hi...! need to generate the salesforce simple json....i had embeded a page in the other page.. and trying to generate the json ..
Page:1:
Commoncontroller:
Note: After editing the input and clicking on the Button, iam not getting the changed dynamic format .
thanks
deepika
Page:1:
<apex:page controller="controllertest1"> <apex:form > Enter Name:<apex:inputText value="{!statedet.stateName}"/> </apex:form> </apex:page>Page:2 : called page1 in page2
<apex:page controller="controllertest1"> <apex:include pageName="testpage1"/> <br/> <apex:form > <apex:commandButton value="JSON GENERATOR" action="{!genereatejson}" reRender="tm" /> <br/> <apex:outputLabel id="tm"> {!jsonstrng}</apex:outputLabel> </apex:form> </apex:page>
Commoncontroller:
public class controllertest1{ public statedetails statedet{get;set;} public string jsonstrng{get;set;} public controllertest1(){ string teststring= ' { "sucess":1,"data": {"stateName": "Andrapradesh", "value": "apx" ,"rating":5 } } '; Map<String, Object> maptest = (Map<String, Object>) JSON.deserializeUntyped(teststring); Object ob = (Object)maptest.get('data'); String srlze = System.JSON.serialize(ob); statedet= (statedetails)System.JSON.deserialize(srlze,statedetails .class); } public void genereatejson(){ JSONGenerator gen = JSON.createGenerator(true); gen.writeStartObject(); gen.writeStringField('stateName',statedet.stateName); gen.writeEndObject(); jsonstrng = gen.getasString(); } //wrapperclass public class statedetails{ public string stateName{get;set;} public string value{get;set;} public integer rating{get;set;} } }
Note: After editing the input and clicking on the Button, iam not getting the changed dynamic format .
thanks
deepika
Can you please try this one it is working for you. If you like this solution please select it as the best answer.
Page:1:
Page 2 : Common controller:
Thnaks.
Deepika..!