Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I serialize some object in .NET using JsonSerializer (on a Windows machine)
The serialized string looks like this:
{
"ItemId":"someID",
"Properties":
{
"Title":"someTitle",
"Text":"someText",
"Time":"someTime"
}
}
Then I send it to a my Linux server, using HttpWebRequest.
On the Linux side I run PHP (using LAMP), when I get it on PHP server the Json string looks exactly as it looks before I send it, but when I try to decode it ( using json_decode($myJsonStr, true) ) I get Syntax Error.
My Json also include some Unicode characters (Hebrew letters)
Any ideas?
Best Regards, Nadav
I'm not sure how you filled your $myJsonStr, but sometimes it's best to decode JSON taking the input directly from PHP's streams, like this:
$data = file_get_contents('php://input');
$json = json_decode($data);
This is the way I use to get around one of those incompatibilities when receiving JSON from third-parties.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am using a library to make API call to the Instagram API. And I am getting a response like this:
POST: https://i.instagram.com/api/v1/feed/timeline/
DATA: is_prefetch=0&feed_view_info=&seen_posts=&phone_id=4c14088a-94b7-49c3-bec3-12caad443c50&reason=pull_to_refresh&battery_level=100
← 200 15.19kB
RESPONSE: {"response": "Random Json Response"}
I want the value of the response key from here.
What is the strategy to parse it? Or this is a special kind of software architecture style like SOAP or REST?
What you're probably looking for is the apache_request_headers() function.
You would use it like so:
$response = apache_request_headers();
print_r($response);
This will generate an array where you will be able to retrieve the information that you need.
The RESPONSE: data is in the JSON format. So you will need to convert it to an array like so:
$responseData = json_decode($responseData, true);
print_r($responseData);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Am fetching data from mysqlite to a string array which i want to submit to PHP then update a mysql table.
Any easy way out, because doesn't seem to work?
I suggest using the network monitor tool to see that the Codename One code is sending out the right data as explained in the IO section of the developer guide.
I notice your PHP code tries to decode JSON into an array whereas your Java code adds a POST array both of which have nothing in common. I don't really know PHP's equivalent for handling an array so I can't help you there. On the Codename One side you can just write the array as JSON by converting it to a JSON String.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have created that needs to take post values and return a JSON encoded array.
That all worked fine until I was told I would need to post the form data with a content-type of application/json.
Since then I cannot return any values from the web service and it is definitely something to do with how I am filtering their post values
Basically I know that it is due to the $_POST values not being set but I can't find what I need to put instead of the $_POST. I tried json_decode($_POST), file_get_contents("php://input") and a number of other ways but I was shooting in the dark a bit.
Any help would be greatly appreciated.
You have empty $_POST. If your web-server wants see data in json-format you need to read the raw input and then parse it with JSON decode You need something like that
$input = file_get_contents('php://input');
$result = json_decode($input);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
as we all know,there is a data type 'resouce' in php!I sometimes can encounter this data type!but I have some problems about this type!
when I have a db connect,I print the data type,it displays"resource(4, mysql link)",
when I create a image,I print the data type,it displays "resource(2, gd)"
i want to know what the number eg.'4','2' means in the "()".
sorry for my bad englis!
When you see resource(4, ...) what that means is that PHP is keeping a reference to a more complex object that isn't a normal PHP object, and thus can't be manipulated directly. It's typically used by libraries that interface with non-PHP code (such as database client libraries and the GD library).
The number is simply the ID number of that particular external object.
These resources are managed by the external library and only really given to PHP as an indirect reference; they only have meaning to the library code that created them.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
still a beginner on php i'm trying to get data from my sql table into an iphone app, i decided to use JSON to do so.
To get my data i use :
mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']);
//select database
#mysql_select_db($config['db_name']) or die( "Unable to select database");
mysql_query('SET CHARACTER SET utf8');
$fet=mysql_query('select * from actualites');
$json = array();
while($r=mysql_fetch_array($fet)){
$json[] = $r;
}
echo $json_data=json_encode($json);
When i print the result into my browser, the json appears but i have a big NOT FOUNT with the following :
Not Found
The requested URL /"http:////www.youtube.com//embed//uspc5ZS-YLI/" was not found on this server.
And so the JSON file is imcomplete ! I have searched the web but found nothing !
What do i do wrong ?
Thank you very much !
EDIT : I have a well formed JSON until i get the Not found.
THe value in the db is :
the result from db looks badly "add_slashes()"-ed somewhere in php code. can you see if that field in db is properly filled? provide sqlfiddle?
EDIT: the code you provided looks normal and should work without problems
Define Content-type for JSON file loaded with PHP.
For JSON:
header('Content-Type: application/json');
For JSON-P:
header('Content-Type: application/javascript');