PHP and json_encode
Cannon Smith (4/23/14 11:05AM)
Welsh Harris (4/23/14 12:28PM)
Cannon Smith (4/23/14 2:06PM)
Koen Van Hooreweghe (4/23/14 7:40PM)
Cannon Smith (4/23/14 11:05 AM)
Hi Everyone,
Iím trying to use PHP from 4D v13.5 to prettify a JSON string, but
canít get it to work. Here is my code:
C_TEXT($tJSON;$tPrettyJSON)
C_BOOLEAN($fResult)
$tJSON:=Get text from pasteboard
$fResult:=PHP
Execute("";"json_encode";$tPrettyJSON;$tJSON;"JSON_PRETTY_PRINT")
If ($fResult=True)
?=A0SET TEXT TO PASTEBOARD($tPrettyJSON)
Else
?=A0ALERT("Error")
End if
If I donít pass the JSON_PRETTY_PRINT constant, it works (although
doesnít prettify), so Iím guessing I shouldnít pass the constant
as
text. Not sure what else to try though.
Does anyone have any ideas? Alternatively, does anyone have some 4D
code to prettify JSON they would be willing to share?
Thanks much!
--
Cannon Smith
Synergy Farm Solutions Inc.
Hill Spring, AB Canada
403-626-3236
<cannon@...
<www.synergyfarmsolutions.com>
Welsh Harris (4/23/14 12:28 PM)
Hey Cannon,
My json component will do that (but you also need to install Miyakoís
oAuth plugin). ?Sorry the docs are so sparse, but the code is
commented:
https://github.com/swelshh/4D_ObjeUtils
This would add white space to json:
$Obj:=Obj_JsonParseText ($Json_t)
$PrettyJson_t:=Obj_JsonStringify ($Obj;JSON_WITH_WHITE_SPACE)
Obj_Release($Obj)
Welsh
Cannon Smith (4/23/14 2:06 PM)
Thanks Welsh and Koen. That gives me a couple things to look into.
I appreciate it!
--
Cannon Smith
Synergy Farm Solutions Inc.
Hill Spring, AB Canada
403-626-3236
<cannon@...
<www.synergyfarmsolutions.com>
On Apr 23, 2014, at 11:28 AM, Welsh Harris
<welsh.harris@... wrote:
color><param>00000,0000,DDEE/param>TThis would add white space to json:
/color>
Koen Van Hooreweghe (4/23/14 7:40 PM)
Hi Cannon,
The constant might be the problem. It is a php constant, not a string ?
and only known within php.
I have something similar with a php call to get a formatted date. I ?
solved the constant handling this way. And from 4D use a string with ?
the name of the constant.
//GET DATETIME STRING
function GetDateTimeString($p1){
switch($p1){
case "DATE_ATOM":
$format = DATE_ATOM;
break;
case "DATE_COOKIE":
$format = DATE_COOKIE;
break;
case "DATE_ISO8601":
$format = DATE_ISO8601;
break;
case "DATE_RFC822":
$format = DATE_RFC822;
break;
case "DATE_RFC850":
$format = DATE_RFC850;
break;
case "DATE_RFC1036":
$format = DATE_RFC1036;
break;
case "DATE_RFC1036":
$format = DATE_RFC1036;
break;
case "DATE_RFC1123":
$format = DATE_RFC1123;
break;
case "DATE_RFC2822":
$format = DATE_RFC2822;
break;
case "DATE_RFC3339":
$format = DATE_RFC3339;
break;
case "DATE_RSS":
$format = DATE_RSS;
break;
case "DATE_W3C":
$format = DATE_W3C;
break;
default:
$format = $p1;
}
return date($format);
}
HTH
Koen
Op 23-apr-14, om 19:05 heeft Cannon Smith het volgende geschreven:
color><param>00000,0000,DDEE/param>IIf I donít pass the
JSON_PRETTY_PRINT constant, it works (although ?
doesnít prettify), so Iím guessing I shouldnít pass the constant
as ?
text. Not sure what else to try though.
/color>
Reply to this message
Summary created 4/23/14 at 3:50PM by Intellex Corporation
Comments welcome at: feedback@intellexcorp.com