Click here to Skip to main content
15,167,425 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: 500 Error Pin
#realJSOP7-Feb-21 10:08
mva#realJSOP7-Feb-21 10:08 
QuestionVS code/Live Server Browser issue Pin
ISHYY4-Feb-21 5:42
MemberISHYY4-Feb-21 5:42 
Questiondeployment using "FTP Passive" Pin
Super Lloyd4-Feb-21 2:56
MemberSuper Lloyd4-Feb-21 2:56 
QuestionPHP 7.4, best practice to establish a database connection Pin
jkirkerx2-Feb-21 9:10
professionaljkirkerx2-Feb-21 9:10 
QuestionWhich will be the best web development course for kids? Pin
Annet Rose14-Jan-21 0:35
MemberAnnet Rose14-Jan-21 0:35 
AnswerRe: Which will be the best web development course for kids? Pin
Richard MacCutchan14-Jan-21 1:37
mveRichard MacCutchan14-Jan-21 1:37 
RantHTML Emails - Printing Pin
Gripper 1070963823-Dec-20 7:08
MemberGripper 1070963823-Dec-20 7:08 
QuestionPHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx19-Dec-20 12:31
professionaljkirkerx19-Dec-20 12: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 16:02
professionalPeter_in_278019-Dec-20 16:02 
GeneralRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx20-Dec-20 9:01
professionaljkirkerx20-Dec-20 9:01 
AnswerRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
Graham Breach20-Dec-20 6:02
MemberGraham Breach20-Dec-20 6:02 
GeneralRe: PHP 4.7, JSON and HTTP response header payload, json_encode Pin
jkirkerx20-Dec-20 9:04
professionaljkirkerx20-Dec-20 9:04 
QuestionI might be wrong about Firefox BOOKMARK behavior ... but Pin
RedDk19-Dec-20 9:36
MemberRedDk19-Dec-20 9:36 
QuestionMVC control libraries Pin
#realJSOP18-Dec-20 3:28
mva#realJSOP18-Dec-20 3:28 
AnswerRe: MVC control libraries Pin
Richard Deeming18-Dec-20 4:04
mveRichard Deeming18-Dec-20 4:04 
GeneralRe: MVC control libraries Pin
#realJSOP18-Dec-20 4:46
mva#realJSOP18-Dec-20 4:46 
GeneralRe: MVC control libraries Pin
Richard Deeming18-Dec-20 4:49
mveRichard Deeming18-Dec-20 4:49 
GeneralRe: MVC control libraries Pin
#realJSOP19-Dec-20 3:10
mva#realJSOP19-Dec-20 3:10 
GeneralRe: MVC control libraries Pin
#realJSOP20-Dec-20 4:51
mva#realJSOP20-Dec-20 4:51 
QuestionDebugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
glen20516-Dec-20 22:55
Memberglen20516-Dec-20 22:55 
AnswerRe: Debugging two ASP.NET projects with Chrome - Failed to launch debug adapter Pin
F-ES Sitecore17-Dec-20 23:51
mveF-ES Sitecore17-Dec-20 23:51 
QuestionPHP4.3 Mod, coloring table rows Pin
jkirkerx1-Dec-20 10:29
professionaljkirkerx1-Dec-20 10:29 
AnswerRe: PHP4.3 Mod, coloring table rows [solved] Pin
jkirkerx1-Dec-20 10:34
professionaljkirkerx1-Dec-20 10:34 
AnswerRe: PHP4.3 Mod, coloring table rows Pin
Richard Deeming1-Dec-20 22:55
mveRichard Deeming1-Dec-20 22:55 
GeneralRe: PHP4.3 Mod, coloring table rows Pin
jkirkerx2-Dec-20 9:30
professionaljkirkerx2-Dec-20 9: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.