Loading ...
Sorry, an error occurred while loading the content.

1764Re: Escape Characters added in C# POST of JSON string to PHP Server

Expand Messages
  • dickwmsinnc
    Oct 19, 2011
    • 0 Attachment
      Your suggestions are just what we needed to get going. We implemented them and are now sending and receiving JSON strings just fine.

      Thank you for your help.

      Dick

      --- In json@yahoogroups.com, Stephan Beal <sgbeal@...> wrote:
      >
      > On Sun, Oct 16, 2011 at 7:15 PM, dickwmsinnc <w3oa@...> wrote:
      >
      > > **
      > >
      > > My json string is:
      > > {"e":"W3OA","h":"bb943d46","s":[["24898.1","K2TQC","1","19","24","False"]],"t":"s"}
      > >
      > The server shows the following result: [spt] =>
      > > {\\"e\\":\\"W3OA\\",\\"h\\":\\"bb943d46\\",\\"s\\":[[\\"24898.1\\",\\"K2TQC\\",\\"1\\",\\"19\\",\\"24\\",\\"False\\"]],\\"t\\":\\"s\\"}
      > >
      > > If I don't precede the json string with "spt=" the server gets an empty
      > > string.
      > >
      >
      > How are you reading this variable server-side? If you post form-urlencoded
      > data (as you are above) then $_POST should work. However, you are simply
      > using:
      >
      > string postData = "spt=" + json;
      >
      > without actually encoding json as form-urlencoded (not that i can see from
      > your code, anyway), so i'm curious as to any of it comes out right.
      >
      > If you want to post raw, unencoded JSON then:
      >
      > a) Set the request content-type of application/json
      > b) POST it as a plain/unencoded string without the leading spt= part.
      > c) on the server you can do:
      >
      > $jsonString = @file_get_contents("php://input");
      > $jsonObj = json_decode($jsonString);
      >
      > That way is much more efficient than form-urlencoding JSON, which is an
      > unnecessary step for both the client and server when dealing solely with
      > JSON data.
      >
      > --
      > ----- stephan beal
      > http://wanderinghorse.net/home/stephan/
      >
      >
      > [Non-text portions of this message have been removed]
      >
    • Show all 4 messages in this topic