Why is json_decode output always null? - php

i have an issue where when i do a return $record in my function below i get valid json in postman pretty view but if i try print_r($record) i have a null at the end of the json.
Then when i try to json_decode the out put is always null for some reason.
If anyone has any ideas why this might be happening i am greatful for your input.
Thanks
function webhook_listener($request_data){
$client = new ZohoCRMClient('Contacts', 'API key Here');
$parameters = $request_data->get_params();
if( !isset( $parameters['contactId'] ) || empty($parameters['contactId']) ){
file_put_contents(plugin_dir_path( __FILE__ ).'invalid.txt', 'No parameter found');
return array( 'error' => 'no_parameter_given' );
}else{
$companyid = $parameters['contactId'];
//file_put_contents(plugin_dir_path( __FILE__ ).'crm.txt', $parameters);
$record = $client->getRecordById()->id($companyid)->request();
$record = json_decode($record);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
throw new RuntimeException("JSON decode error: $error");
}
echo $company = $record[1]['data']['Company'];
}
}
JSON:
{"1":{"index":1,"data":{"CONTACTID":"3345923000000546002","SMOWNERID":"3345923000000158021","Contact Owner":"Frank Rosa","First Name":"Administrator","Last Name":"Ian","Email":"poojarajan3ellc#gmail.com","Created Time":"2018-09-19 14:32:35","Modified Time":"2018-09-20 02:48:51","Full Name":"Administrator Ian","Description":"Equity and Empowerment through Education. It is the Mission of 3e LLC to promote equity and empowerment for all students through engaging professional development for educators and parents, one-on-one coaching for teacher efficacy, and mentoring services for youth to promote enrichment and success. For the empowered, we offer editing, transcribing, and ghostwriting services to ensure your voice is heard.","Last Activity Time":"2018-09-20 02:48:51","Instagram Url":"http:\/\/www.instagram.com\/3e_llc","Company":"3ELLC","Website":"https:\/\/www.3ellc.org","Phone_1":"(727) 420-1050","Full Address":"2152 Arcadia Rd, Holiday, FL 34690, USA","Facebook Url":"http:\/\/www.facebook.com\/3eLLC\/","Logo Url":"https:\/\/dev.energypages.com\/wp-content\/uploads\/2018\/05\/header-logo-57.png","Twitter Url":"http:\/\/www.twitter.com\/3e_llc","Membership Level":"Basic","Select Service":"Technology","User ID":"347"}}}
var_dump output:
array(1) {
[1]=>
object(CristianPontes\ZohoCRMClient\Response\Record)#2068 (2) {
["index"]=>
int(1)
["data"]=>
array(22) {
["CONTACTID"]=>
string(19) "3345923000000546002"
["SMOWNERID"]=>
string(19) "3345923000000158021"
["Contact Owner"]=>
string(10) "Frank Rosa"
["First Name"]=>
string(13) "Administrator"
["Last Name"]=>
string(3) "Ian"
["Email"]=>
string(25) "poojarajan3ellc#gmail.com"
["Created Time"]=>
string(19) "2018-09-19 14:32:35"
["Modified Time"]=>
string(19) "2018-09-20 02:48:51"
["Full Name"]=>
string(17) "Administrator Ian"
["Description"]=>
string(407) "Equity and Empowerment through Education. It is the Mission of 3e LLC to promote equity and empowerment for all students through engaging professional development for educators and parents, one-on-one coaching for teacher efficacy, and mentoring services for youth to promote enrichment and success. For the empowered, we offer editing, transcribing, and ghostwriting services to ensure your voice is heard."
["Last Activity Time"]=>
string(19) "2018-09-20 02:48:51"
["Instagram Url"]=>
string(31) "http://www.instagram.com/3e_llc"
["Company"]=>
string(5) "3ELLC"
["Website"]=>
string(21) "https://www.3ellc.org"
["Phone_1"]=>
string(14) "(727) 420-1050"
["Full Address"]=>
string(39) "2152 Arcadia Rd, Holiday, FL 34690, USA"
["Facebook Url"]=>
string(30) "http://www.facebook.com/3eLLC/"
["Logo Url"]=>
string(73) "https://dev.energypages.com/wp-content/uploads/2018/05/header-logo-57.png"
["Twitter Url"]=>
string(29) "http://www.twitter.com/3e_llc"
["Membership Level"]=>
string(5) "Basic"
["Select Service"]=>
string(10) "Technology"
["User ID"]=>
string(3) "347"
}
}
}
null
Output above is the raw view in postman. and in pretty view i got this error (Unexpected 'a')

All the answers here on how to parse jSON were correct. But i was using a php library for my link to zoho which handles the data differently, so i had to do a foreach on my response from the API then json_encode() the data and json_decode() to get the values.
Library i am using: https://github.com/cristianpontes/zoho-crm-client-php
foreach($record as $records){
$payload = $records->getData();
$payload = json_encode($payload);
$payload = json_decode($payload, true);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
throw new RuntimeException("JSON decode error: $error");
}
$company = $payload['Company'];
}
Thanks to everyone that helped especially #miken32

Related

Group URLs into single object output in API response

So I'll try to explain this as best as possible, but I'm having some issues with how the links are being rendered so I'll go into more detail below.
Here is the full method:
public function link_urls($text)
{
if (!$urls = $this->get('entities', 'urls')) {
return $text;
}
foreach ($urls as $url) {
$text = str_replace(
$url->url,
'' . $url->display_url . '',
$text
);
}
return $text;
}
What this method does is it takes the ['text'] param response from the API and then it goes through and searches for URLs and appends HTML outputs.
Let's say that we have $text which outputs the following tweet data:
string(316) “As we continue to celebrate #BlackHistoryMonth , our next Black Artist Spotlight 🎨 is local painter #EbonyLewisArt https:// t.co/LaRa7GDk4i”
This particular tweet has 4 images, but Twitter groups them all into one "tweet" link as shown above.
Next, I'm checking the tweets $urls object that it returns, which is $urls = $this->get('entities', 'urls') which gives me:
object(stdClass)#1958 (5) {
["start"]=>
int(115)
["end"]=>
int(138)
["url"]=>
string(23) "https:// t.co/LaRa7GDk4i"
["expanded_url"]=>
string(65) "https://twitter.com/dallasmavs/status/1491079415375495168/photo/1"
["display_url"]=>
string(26) "pic.twitter.com/LaRa7GDk4i"
}
object(stdClass)#1737 (5) {
["start"]=>
int(115)
["end"]=>
int(138)
["url"]=>
string(23) "https:// t.co/LaRa7GDk4i"
["expanded_url"]=>
string(65) "https://twitter.com/dallasmavs/status/1491079415375495168/photo/1"
["display_url"]=>
string(26) "pic.twitter.com/LaRa7GDk4i"
}
object(stdClass)#1735 (5) {
["start"]=>
int(115)
["end"]=>
int(138)
["url"]=>
string(23) "https:// t.co/LaRa7GDk4i"
["expanded_url"]=>
string(65) "https://twitter.com/dallasmavs/status/1491079415375495168/photo/1"
["display_url"]=>
string(26) "pic.twitter.com/LaRa7GDk4i"
}
object(stdClass)#1736 (5) {
["start"]=>
int(115)
["end"]=>
int(138)
["url"]=>
string(23) "https:// t.co/LaRa7GDk4i"
["expanded_url"]=>
string(65) "https://twitter.com/dallasmavs/status/1491079415375495168/photo/1"
["display_url"]=>
string(26) "pic.twitter.com/LaRa7GDk4i"
}
Here is the problem:
I'm calling a foreach loop which grabs all the URLs and converts $url->url with an <a> tag and displaying the $url->display_url as shown below:
foreach ($urls as $url) {
$text = str_replace(
$url->url,
'' . $url->display_url . '',
$text
);
}
The problem is that $text just has one URL to look on and the foreach loops through 4 times which causes issues and outputs the following:
As we continue to celebrate #BlackHistoryMonth , our next Black Artist
Spotlight 🎨 is local painter #EbonyLewisArt
pic.twitter.com/LaRa7GDk4i”
target=”_blank”>pic.twitter.com/LaRa7GDk4i”
target=”_blank”>pic.twitter.com/LaRa7GDk4i”
target=”_blank”>pic.twitter.com/LaRa7GDk4i
When I have one $urls object with one link in $text it's perfectly fine, the problem shows up when Twitter groups the links in $text and outputs multiple objects.
Here are my questions:
If there are multiple objects which are exactly the same, can I delete the other objects and just output one?
In the foreach, if the objects are the same, can I somehow skip all but one?
All help is appreciated on this!
Kindly change your foreach loop to this
foreach ($urls as $url) {
if( strpos($text, $url->url) !== false ){
$text = str_replace(
$url->url,
'' . $url->display_url . '',
$text
);
break;
}
}

Why am I Not receiving a notification when my FedEx package is delivered?

I'm using FedEx web services and jeremy-dunn/php-fedex-api-wrapper and attempting to have FedEx send me a plaintext email notification when a package has been delivered. I am using a third party for order fulfillment, and they have and use a different FedEx account that is not mine. (Maybe this is the problem?)
I can track the packages just fine, and when I attempt to subscribe to the delivery notification, the response from FedEx seems to indicate success. I am in testing mode. I'm NOT currently in production mode, in case that matters.
My request uses the following function:
function fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender )
{
global $fedexApiMode;
if( ! is_array( $recipient ) OR ! isset( $recipient['email_addr'] ) )
return FALSE;
if( ! is_array( $sender ) OR ! isset( $sender['email_addr'], $sender['name'] ) )
return FALSE;
$userCredential = new ComplexType\WebAuthenticationCredential();
$userCredential->setKey(FEDEX_KEY)
->setPassword(FEDEX_PASSWORD);
$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
$webAuthenticationDetail->setUserCredential($userCredential);
$clientDetail = new ComplexType\ClientDetail();
$clientDetail->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
->setMeterNumber(FEDEX_METER_NUMBER);
$version = new ComplexType\VersionId();
$version->setMajor(5)
->setIntermediate(0)
->setMinor(0)
->setServiceId('trck');
$localization = new ComplexType\Localization();
$localization->setLocaleCode("US")
->setLanguageCode("EN");
$emailRecip = new ComplexType\EMailNotificationRecipient();
$emailRecip->setEMailNotificationRecipientType(SimpleType\EMailNotificationRecipientType::_SHIPPER)
->setEMailAddress( $recipient['email_addr'] )
->setLocalization($localization)
->setFormat(SimpleType\EMailNotificationFormatType::_TEXT)
->setNotificationEventsRequested([
SimpleType\EMailNotificationEventType::_ON_DELIVERY,
SimpleType\EMailNotificationEventType::_ON_EXCEPTION,
SimpleType\EMailNotificationEventType::_ON_SHIPMENT,
SimpleType\EMailNotificationEventType::_ON_TENDER
]);
$emailNotificationDetail = new ComplexType\EMailNotificationDetail();
$emailNotificationDetail->setPersonalMessage('Shipment Status Notification')
->setRecipients([$emailRecip]);
$request = new ComplexType\TrackNotificationRequest();
$request->setWebAuthenticationDetail($webAuthenticationDetail)
->setClientDetail($clientDetail)
->setVersion($version)
->setTrackingNumber( $trackingNumber )
->setSenderEMailAddress( $sender['email_addr'] )
->setSenderContactName( $sender['name'] )
->setNotificationDetail($emailNotificationDetail);
$trackServiceRequest = new TrackService\Request();
if( $fedexApiMode == 'production' )
$trackServiceRequest->getSoapClient()->__setLocation(TrackService\Request::PRODUCTION_URL);
$response = $trackServiceRequest->getGetTrackNotificationReply($request, TRUE);
return $response;
}
I use that function like this:
$trackingNumber = '781893213291';
$recipient = [
'email_addr' => 'email#example.com'
];
$sender = [
'email_addr' => 'email#example.com',
'name' => 'My Name'
];
$response = fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender );
echo '<pre>';
var_dump($response);
echo '</pre>';
And my response looks like this:
object(stdClass)#28 (6) {
["HighestSeverity"]=>
string(7) "SUCCESS"
["Notifications"]=>
object(stdClass)#29 (5) {
["Severity"]=>
string(7) "SUCCESS"
["Source"]=>
string(4) "trck"
["Code"]=>
string(1) "0"
["Message"]=>
string(35) "Request was successfully processed."
["LocalizedMessage"]=>
string(35) "Request was successfully processed."
}
["Version"]=>
object(stdClass)#30 (4) {
["ServiceId"]=>
string(4) "trck"
["Major"]=>
int(5)
["Intermediate"]=>
int(0)
["Minor"]=>
int(0)
}
["DuplicateWaybill"]=>
bool(false)
["MoreDataAvailable"]=>
bool(false)
["Packages"]=>
object(stdClass)#31 (6) {
["TrackingNumber"]=>
string(12) "781893213291"
["TrackingNumberUniqueIdentifiers"]=>
string(23) "12018~781893213291~FDEG"
["CarrierCode"]=>
string(4) "FDXG"
["ShipDate"]=>
string(10) "2018-07-17"
["Destination"]=>
object(stdClass)#32 (4) {
["City"]=>
string(13) "SAN FRANCISCO"
["StateOrProvinceCode"]=>
string(2) "CA"
["CountryCode"]=>
string(2) "US"
["Residential"]=>
bool(false)
}
["RecipientDetails"]=>
object(stdClass)#33 (1) {
["NotificationEventsAvailable"]=>
array(6) {
[0]=>
string(11) "ON_DELIVERY"
[1]=>
string(12) "ON_EXCEPTION"
[2]=>
string(12) "ON_EXCEPTION"
[3]=>
string(12) "ON_EXCEPTION"
[4]=>
string(12) "ON_EXCEPTION"
[5]=>
string(12) "ON_EXCEPTION"
}
}
}
}
So it appears that I have subscribed, and that I should receive an email notification when the package is delivered, but the email never arrives. So I need help to know what's wrong with my code, or what's wrong with what I'm doing. I believe I understand what I'm doing, but no success.
https://www.fedex.com/us/developer/WebHelp/ws/2014/dvg/WS_DVG_WebHelp/26_Shipment_Notification_in_the_Ship_Request.htm
Here it says you cannot receive an email in test enviro
1) In test mode, notifications are not sent. With the production key (production mode), notifications are sent. This is what I was expecting.
2) My code and the response I am getting back are fine.
3) Adding a track notification for a package that was not sent through my account works just fine. There is no restriction to adding track notifications, other than there may only be a total of 4.

imap_body() returning empty string

Hello fellow developers,
Im currently trying to read all emails with imap. Im trying to get the header infos with imap_headerinfo and the body with imap_fetchbody.
However, I get all the headerinfo but I only get an empty string as a return from the fetchbody function. I hope someone can help me
$this->inbox = imap_open($server, $user, $password);
// Header und Body der Email auslesen
$emails = imap_search($this->inbox,'ALL');
foreach($emails as $k) {
$this->email_contents[$k] = array(
'header' => imap_headerinfo($this->inbox, $k),
'body' => imap_fetchbody($this->inbox, $k, '1')
);
}
imap_close($this->inbox);
fetch_structure
object(stdClass)#65 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "MIXED"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#66 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(36) "------------CC4C1146391EA6C129642420"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#67 (12) {
["type"]=>
int(0)
["encoding"]=>
int(1)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "PLAIN"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(30)
["bytes"]=>
int(590)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
[0]=>
object(stdClass)#68 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
[1]=>
object(stdClass)#69 (2) {
["attribute"]=>
string(6) "format"
["value"]=>
string(6) "flowed"
}
}
}
[1]=>
object(stdClass)#70 (13) {
["type"]=>
int(5)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "JPEG"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["bytes"]=>
int(1036)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(1)
["dparameters"]=>
array(1) {
[0]=>
object(stdClass)#71 (2) {
["attribute"]=>
string(8) "filename"
["value"]=>
string(11) "logo_sm.jpg"
}
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#72 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(11) "logo_sm.jpg"
}
}
}
}
}
imap-fetchbody() works unusually when handling attached email messages and it's behaviour is inconsistent.
I was going to re-write this but to be honest the author atamido does a fantastic job of showing why this happens so i'll humbly cite his lead comment from this:: http://php.net/manual/en/function.imap-fetchbody.php he also includes an example of how to extract the body
imap-fetchbody() will decode attached email messages inline with the
rest of the email parts, however the way it works when handling
attached email messages is inconsistent with the main email message.
With an email message that only has a text body and does not have any mime attachments, imap-fetchbody() will return the following
for each requested part number:
(empty) - Entire message
0 - Message header
1 - Body text
With an email message that is a multi-part message in MIME format, and contains the message text in plain text and HTML, and has
a file.ext attachment, imap-fetchbody() will return something like the
following for each requested part number:
(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - file.ext
Now if you attach the above email to an email with the message text in plain text and HTML, imap_fetchbody() will use this type of
part number system:
(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - MESSAGE/RFC822 (entire attached message)
2.0 - Attached message header
2.1 - TEXT/PLAIN
2.2 - TEXT/HTML
2.3 - file.ext
Note that the file.ext is on the same level now as the plain text and
HTML, and that there is no way to access the MULTIPART/ALTERNATIVE in
the attached message.
Here is a modified version of some of the code from previous posts
that will build an easily accessible array that includes accessible
attached message parts and the message body if there aren't multipart
mimes. The $structure variable is the output of the
imap_fetchstructure() function. The returned $part_array has the
field 'part_number' which contains the part number to be fed directly
into the imap_fetchbody() function.
<?php
function create_part_array($structure, $prefix="") {
//print_r($structure);
if (sizeof($structure->parts) > 0) { // There some sub parts
foreach ($structure->parts as $count => $part) {
add_part_to_array($part, $prefix.($count+1), $part_array);
}
}else{ // Email does not have a seperate mime attachment for text
$part_array[] = array('part_number' => $prefix.'1', 'part_object' => $obj);
}
return $part_array;
}
// Sub function for create_part_array(). Only called by create_part_array() and itself.
function add_part_to_array($obj, $partno, & $part_array) {
$part_array[] = array('part_number' => $partno, 'part_object' => $obj);
if ($obj->type == 2) { // Check to see if the part is an attached email message, as in the RFC-822 type
//print_r($obj);
if (sizeof($obj->parts) > 0) { // Check to see if the email has parts
foreach ($obj->parts as $count => $part) {
// Iterate here again to compensate for the broken way that imap_fetchbody() handles attachments
if (sizeof($part->parts) > 0) {
foreach ($part->parts as $count2 => $part2) {
add_part_to_array($part2, $partno.".".($count2+1), $part_array);
}
}else{ // Attached email does not have a seperate mime attachment for text
$part_array[] = array('part_number' => $partno.'.'.($count+1), 'part_object' => $obj);
}
}
}else{ // Not sure if this is possible
$part_array[] = array('part_number' => $prefix.'.1', 'part_object' => $obj);
}
}else{ // If there are more sub-parts, expand them out.
if (sizeof($obj->parts) > 0) {
foreach ($obj->parts as $count => $p) {
add_part_to_array($p, $partno.".".($count+1), $part_array);
}
}
}
}
?>

how to parse a json mailgun sendmessage response in php?

Here is my code:
$this->view->assign('mail', $mail);
$mg = new Mailgun($this->getMailgunAPIKey());
$domain = "sandbox1111.mailgun.org";
$res = $mg->sendMessage($domain, array('from' => 'bob#sandbox3445.mailgun.org',
'to' => 'mee#xxxxx.com',
'subject' => $mail->getSubject(),
'text' => $mail->getBody()));
var_dump( $res);
and here is what gets printed out by the var_dump:
object(stdClass)#228 (2) { ["http_response_body"]=> object(stdClass)#223 (2) { ["message"]=> string(18) "Queued. Thank you." ["id"]=> string(52) "<20131211155824.31559.48115#sandbox1111.mailgun.org>" } ["http_response_code"]=> int(200) }
I tried var_dump( json_decode($res)); but that prints out NULL. How do I access the ["http_response_code"] for instance?
ANSWER:
var_dump( $res);
echo __LINE__.'<br/><br/>';
var_dump( $res->http_response_body );
echo __LINE__.$res->http_response_code.'<br/><br/>';
echo $res->http_response_body->message.'<br/><br/>';
prints
object(stdClass)#228 (2) { ["http_response_body"]=> object(stdClass)#223 (2) { ["message"]=> string(18) "Queued. Thank you." ["id"]=> string(52) "<20131211161740.16663.18744#sandbox3445.mailgun.org>" } ["http_response_code"]=> int(200) } 150
object(stdClass)#223 (2) { ["message"]=> string(18) "Queued. Thank you." ["id"]=> string(52) "<20131211161740.16663.18744#sandbox3445.mailgun.org>" } 152200
Queued. Thank you.
Your variable is already json_decoded, with the second parameter to false.
json_decode() works with objects by default (default = false in this case), if you want an array, use the 2nd parameter true, see http://php.net/json_decode.
I prefere object notation.
How do I access the ["http_response_code"] for instance?
$res->http_response_body
echo $res->http_response_body->message
//prints "Queued. Thank you."

Putting JSON data into a variable in PHP

EDIT: I don't think the final output looks like JSON. If not, what is it?
I have this code:
$url = 'http://eligibility.sc.egov.usda.gov/eligibility/eligibilityservice?eligibilityType=Property&requestString=<?xml version="1.0"?><Eligibility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/var/lib/tomcat5/webapps/eligibility/Eligibilitywsdl.xsd"><PropertyRequest StreetAddress1="'.$street.'" StreetAddress2="" StreetAddress3="" City="'.$city.'" State="'.$state.'" County="" Zip="'.$zip.'" Program="RBS"></PropertyRequest></Eligibility>';
$url_arr = explode( 'requestString=', $url );
$xml = simplexml_load_string( $url_arr[ 1 ] ); // requires allow_url_fopen to be on
$elg = (string)$xml->Property[Eligibility];
var_dump($xml);
$xml = simplexml_load_file($url); // requires allow_url_fopen to be on
$elg = json_encode((string)$xml->Property[Eligibility]);
var_dump($elg);
Which out puts this array:
object(SimpleXMLElement)#1 (1) {
["PropertyRequest"]=> object(SimpleXMLElement)#2 (1) {
["#attributes"]=> array(8) {
["StreetAddress1"]=> string(13) "7865 ILLINOIS"
["StreetAddress2"]=> string(0) ""
["StreetAddress3"]=> string(0) ""
["City"]=> string(10) "CASEYVILLE"
["State"]=> string(2) "IL"
["County"]=> string(0) ""
["Zip"]=> string(5) "62232"
["Program"]=> string(3) "RBS"
}
}
}
string(12) ""InEligible""
I just want to grab the string(12) ""InEligible"" portion. How would I put this into a variable?
From your code there $elg already holds this value, and it is a variable.
EDIT: I don't think the final output looks like JSON. If not, what is it?
string(12) ""InEligible""
That's JSON. A string in JSON is enclosed in quotes, no more, no less.

Categories