You need to sign in to do that
Don't have an account?
Kamil Mieczakowski
parsing json de
I am attempting to parse MatterMark's API, but I am planning to do so selectively, picking only the value pairs that are relevant. The example JSON response is available to be viewed in MatterMark's documentation (here).
Here's my Wrapper:
And the Parser:
I am trying to get it displayed on this page, but all I am getting is a blank page...
I've been trying to debug it with no success, any ideas why this may be not working?
Here's my Wrapper:
public class MMarkWrapper { public class mmark_company_profile { public string name {get;set;} public string description {get;set;} public string employees {get;set;} public string employees_6_months_ago {get;set;} public string last_funding_amount {get;set;} public string last_funding_date {get;set;} public string country {get;set;} public string total_funding {get;set;} public string acquired_by {get;set;} public List<mmark_funding_round> mmark_funding_rounds {get;set;} } public class mmark_funding_round { public string amount {get;set;} public string transaction_currency {get;set;} public string series {get;set;} public string funding_date {get;set;} public string investors {get;set;} } public List<mmark_company_profile> mmark_company_profile_list {get; set;} }
And the Parser:
public class MMarkParser { public MMarkWrapper wrapper { get; set; } public void parse() { //request class HTTPRequest request = new HTTPRequest(); request.setEndpoint(Label.MatterMarkAPI+'/domains/'+ 'marketinvoice.com' +'/companies?key=' +'c878f447941828d91d53ffbebae068cdb7624fb257cca98e2672e8148e039c1c'); request.setMethod('GET'); //response class HTTP h = new HTTP(); HTTPResponse response = h.send(request); wrapper = (MMarkWrapper) JSON.deserialize(response.getBody(), MMarkWrapper.class); System.debug(wrapper); } }
I am trying to get it displayed on this page, but all I am getting is a blank page...
<apex:page controller="MMarkParser"> <apex:form > <apex:pageBlock title="MMarkParserResponse"> <apex:pageBlockButtons > <apex:commandButton value="submit" action="{!parse}" reRender="mmark_company_profile"/> </apex:pageBlockButtons> <apex:pageBlockSection id="mmark_company_profile" columns="1"> <apex:repeat value="{!wrapper.mmark_company_profile_list}" var="mmark_company_profile"> <apex:pageBlockSection columns="2"> <apex:facet name="header">Company {!mmark_company_profile.name}</apex:facet> <apex:pageBlockSectionItem > <apex:outputLabel value="Description" for="description" /> <apex:outputText value="{!mmark_company_profile.description}" id="description" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Employees" for="employees" /> <apex:outputText value="{!mmark_company_profile.employees}" id="employees" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection columns="1"> <apex:facet name="header">Funding {!mmark_company_profile.name} Series</apex:facet> <apex:pageBlockTable value="{!mmark_company_profile.mmark_funding_rounds}" var="item" id="mmark_funding_rounds"> <apex:column value="{!item.amount}" headerValue="Amount" /> <apex:column value="{!item.transaction_currency}" headerValue="Transaction Currency" /> <apex:column value="{!item.series}" headerValue="Series" /> <apex:column value="{!item.funding_date}" headerValue="Funding Date" /> </apex:pageBlockTable> </apex:pageBlockSection> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
I've been trying to debug it with no success, any ideas why this may be not working?
Then use the following to deserialize it
I would start with the simpilest visualforce page and see if this works
If this doesn't work, please provide the output of the debug call
All Answers
The problem is that your structure for your wrapper object is not correct. Looking at the documenation [1] for the /companies endpoint, you need a different wrapper all together. If you where to specify the company id in the url, then you could use what you have with this endpoint [2] and deserialize it.
However for the list method [1] you need a different approach
then you would deserialize it like so NOTE: This code has not been tested and may contain typographical or logical errors
[1] https://docs.mattermark.com/api_v1/companies_list/index.html
[2] https://docs.mattermark.com/api_v1/company_details/index.html
However I do not think that a wrong wrapper is the reason here.
That's the API response I am getting from my request class:
Then use the following to deserialize it
I would start with the simpilest visualforce page and see if this works
If this doesn't work, please provide the output of the debug call