I am looking something like emberjs-data but for PHP?
Longest description:
I am looking class in PHP to generate JSON for emberjs in standard format and get this data in emberjs. And with other side, i want send data from emberjs to PHP using the same JSON standard.
In fact, you are looking for the PHP equivalent of ActiveModelSerializers.
Did you looked at http://www.phpactiverecord.org/docs/ActiveRecord/Serialization?
Related
right now im learning about Opencart API. form opencart documentation Documentation every example write with json format.
however when i test it on postman. i test API for add product to cart. i can't put the json raw format body. i need to put the data on form-data.
this example result when i put raw json body format. and return empty array
and this result wheni put data on form-data
does opencart can't receive json format when do API call?
opencart documentation Documentation every example write with json format.
No, it doesn't.
The examples use a Python library and Python syntax.
The value of data looks superficially like JSON but is Python. The library takes that data and, according to the docs, converts it to form encoded data.
data – the body to attach to the request. If a dictionary or list of tuples [(key, value)] is provided, form-encoding will take place.
The API doesn't appear to support JSON.
I see that .NET can encode the dates like /Date(1365004652303-0500)/ when it generate the JSON response for a RestFull API response (for example read here).
My question is how can I generate the same output for my date properties inside an object when I use json_encode function to encode that object in the PHP.
I don't mean how to do it with an algorithm. I know how to write the algorithm! I would like to do it in a way that the front-end could understand this property is a date! I don't want to transfer it as a simple text!
I have a database hosted on server whose field values have to be passed to my app. I would like to do with PHP. But people suggest me to use JSON too. Is JSON required? Please guide me how to pass the field values to android app.
JSON means JavaScript Object Notation and it's just a way of formatting your output in a standard way.
So, if you'd like to pass data from a database to an application, you'd need to implement a small API. This can be done using PHP. At this point, you can access data from your database using a browser and parametrizing your queries using url parameters.
PHP can render the data in a simple HTML table for example, but this is just a way of presenting your data. You can also use JSON.
This means that if you need the badges a user has earned, you'll use something like this:
<link_to_your_api>/index.php?method=getBadges&user=<user>
This in turn, will make a request to the database
<?php
// 1. connect to database
// 2. query for the information
// 3. get the result as array
$result = $db->getData();
echo json_encode($result);
?>
This is just an example, hope it helps.
link to json documentation: http://www.json.org/
You pass the data to your app, when it makes a request to your PHP script. JSON is handy because you can package your data in a format, that is both well readable by humans and machines. You can use the gson library then, to process the JSON data in your app.
Create REST api using any server side script PHP,nodejs or any you like which returns JSON response
call the rest api using http request which returns JSOn text
decode the JSON string to JSON object and use with your android code
The goal is to unserialize a PHP serialized string and get sutable object in C#
Is there any way to make this possible in C#(.Net)?
To be more specific:
We need to make an application which comunicates (Via HTTP) to specific website which returns the needed information. Fortunately/unfortunately we dont have permission to website so the data (array mostly) that is returned from website is PHP serialized.
I suppose using JSON as an intermediary step could be useful.
You should probably write it to XML or JSON. You can construct your C# object back from the XML
Edit: Looks like there is already a XML serializer for PHP
Have an old project that someone did in PHP and am attempting to convert it over to Rails. Am encountering an issue when trying to iterate through a multiple array in rails.
The array as stored in the DB looks like this:
a:5:{i:0;s:8:"Director";i:1;s:11:"Shareholder";i:2;s:14:"Vice President";i:3;s:9:"Secretary";i:4;s:9:"Treasurer";}
Am trying to display the String values such as "Director" and "Shareholder".
Does the DB field need to be changed to a different format to work?
How would this be done in rails?
Thank you in advance
That looks like the output of PHP's serialize function to me.
If you have PHP around or don't mind installing it to help with the data migration, then I'd write a short PHP script to convert those columns to JSON using PHP's unserialize and json_encode functions: read a value, unserialize it, json_encode the result, write it back into the database (all in PHP).
After that, you should be able to use ActiveRecord's serialize with JSON as the storage format:
class Model < ActiveRecord::Base
serialize :whatever_it_is_called, JSON
end
You could also use YAML (the default for ActiveRecord's serialize) if you had YAML support in PHP-land.
If you don't want to touch PHP at all, then you'll have to write Ruby parser for PHP's serialize format (which seems to be well documented in the PHP docs) and hook that up to ActiveRecord's serialize.
You will of course be working with a copy of the real database for all this work.