Click here to Skip to main content
15,879,326 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: 500 Error Pin
#realJSOP7-Feb-21 9:08
mve#realJSOP7-Feb-21 9:08 
QuestionVS code/Live Server Browser issue Pin
ISHYY4-Feb-21 4:42
ISHYY4-Feb-21 4:42 
Questiondeployment using "FTP Passive" Pin
Super Lloyd4-Feb-21 1:56
Super Lloyd4-Feb-21 1:56 
QuestionPHP 7.4, best practice to establish a database connection Pin
jkirkerx2-Feb-21 8:10
professionaljkirkerx2-Feb-21 8:10 
QuestionWhich will be the best web development course for kids? Pin
Annet Rose13-Jan-21 23:35
Annet Rose13-Jan-21 23:35 
AnswerRe: Which will be the best web development course for kids? Pin
Richard MacCutchan14-Jan-21 0:37
mveRichard MacCutchan14-Jan-21 0:37 
RantHTML Emails - Printing Pin
Gripper 1070963823-Dec-20 6:08
Gripper 1070963823-Dec-20 6:08 
QuestionPHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx19-Dec-20 11:31
professionaljkirkerx19-Dec-20 11:31 
I'm SMH on this.

Normally I really never look at the HTTP response payload and just assume it works. But this is a total hack on PHP 4.7 to tweak it to do modern things. I'm confused here, and really just looking for an explanation of why, so here goes.

I wrote this in PHP 4.7; being limited with what I can do, I hand crafted some JSON, and used a hack to encode it.
C#
header('Content-Type: application/json; charset=utf-8');
$json = '{
    "projectNumber":' . $sess_proj_no . ',
    "projectStage":"' . $sess_proj_stage . '",
    "newVersion":' . $new_version_no . ', 
    "undefinedValue":{
        "projectNumber":"' . $projectNumber . '",
        "variableContingencyCost":"' . $variableContingencyValue . '",
        "variableContingencyValue":"' . $variableContingencyRate . '",
        "actualPlusContingencyCost":"' . $actualPlusContingencyCost . '"  
    }
}';

$jsonTest = '{ "test": "result" }';
$jsonEncode = json_encode($jsonTest);
echo $json;
ob_end_flush();
With encoding, adding slashes to the double quotes,
SyntaxError: JSON.parse: expected property name or '}' at line 2 column 13 of the JSON data
"{
            \"projectNumber\":2549,
            \"projectStage\":\"engineering\",
            \"newVersion\":0, 
            \"undefinedValue\":{
                \"projectNumber\":\"\",
                \"variableContingencyCost\":\"\",
                \"variableContingencyValue\":\"\",
                \"actualPlusContingencyCost\":\"\"  
            }
        }"
Without encoding, no slashes to the double quotes, I get a clean HTTP response payload without errors.
{
    "projectNumber": 2549,
    "projectStage": "engineering",
    "newVersion": 0,
    "undefinedValue": {
        "projectNumber": "",
        "variableContingencyCost": "",
        "variableContingencyValue": "",
        "actualPlusContingencyCost": ""
    }
}
I always thought JSON had to be encoded during transport, and then decoded to consume it.
Unless json_encode is meant to convert JSON created with a class, into a string without slashes. or it has something to do with echo and just spitting out text.
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
Peter_in_278019-Dec-20 15:02
professionalPeter_in_278019-Dec-20 15:02 
GeneralRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx20-Dec-20 8:01
professionaljkirkerx20-Dec-20 8:01 
AnswerRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
Graham Breach20-Dec-20 5:02
Graham Breach20-Dec-20 5:02 
GeneralRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx20-Dec-20 8:04
professionaljkirkerx20-Dec-20 8:04 
QuestionI might be wrong about Firefox BOOKMARK behavior ... but Pin
RedDk19-Dec-20 8:36
RedDk19-Dec-20 8:36 
QuestionMVC control libraries Pin
#realJSOP18-Dec-20 2:28
mve#realJSOP18-Dec-20 2:28 
AnswerRe: MVC control libraries Pin
Richard Deeming18-Dec-20 3:04
mveRichard Deeming18-Dec-20 3:04 
GeneralRe: MVC control libraries Pin
#realJSOP18-Dec-20 3:46
mve#realJSOP18-Dec-20 3:46 
GeneralRe: MVC control libraries Pin
Richard Deeming18-Dec-20 3:49
mveRichard Deeming18-Dec-20 3:49 
GeneralRe: MVC control libraries Pin
#realJSOP19-Dec-20 2:10
mve#realJSOP19-Dec-20 2:10 
GeneralRe: MVC control libraries Pin
#realJSOP20-Dec-20 3:51
mve#realJSOP20-Dec-20 3:51 
QuestionDebugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
glen20516-Dec-20 21:55
glen20516-Dec-20 21:55 
AnswerRe: Debugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
F-ES Sitecore17-Dec-20 22:51
professionalF-ES Sitecore17-Dec-20 22:51 
QuestionPHP4.3 Mod, coloring table rows Pin
jkirkerx1-Dec-20 9:29
professionaljkirkerx1-Dec-20 9:29 
AnswerRe: PHP4.3 Mod, coloring table rows [solved] Pin
jkirkerx1-Dec-20 9:34
professionaljkirkerx1-Dec-20 9:34 
AnswerRe: PHP4.3 Mod, coloring table rows Pin
Richard Deeming1-Dec-20 21:55
mveRichard Deeming1-Dec-20 21:55 
GeneralRe: PHP4.3 Mod, coloring table rows Pin
jkirkerx2-Dec-20 8:30
professionaljkirkerx2-Dec-20 8:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.