问题
I am trying to understand the basic flow of a system consisting of:
C#
client/program/app which will query thePHP
server.PHP
server.Couchbase
server running onLinux
.
On the client side I have some classes, class MyClass {int,string,list etc}
.
Based on other questions and answers, the flow should look like this:
C#
client class->serialize to JSON
-> post as string to PHP
page-> (on PHP
page) deserialize JSON
string to PHP
class ->posting to Couchbase
-> getting result -> serialize to JSON
->post as JSON
string and return to the C#
client -> etc
- Is that correct? Any suggestions?
- What are the best tools/packages, easiest way to serialize from
JSON
and toJSON
inPHP
?
Thanks for your help!
回答1:
Couchbase 2.0 is a database that allows you to store document directly. As soon as you have the JSON string you can store it into Couchbase using the PHP Client SDK.
That said, if you have a PHP object and you can use the json_encode()/json_decode() functions that are available in PHP.
You can take a look the the Getting Started and Tutorial from Couchbase: - http://www.couchbase.com/docs/couchbase-sdk-php-1.1/tutorial.html
Also you can look at this interested library that allows you to develop with PHP and Couchbase easily: - https://github.com/Basement/Basement You can look to use it, or look to see how it uses PHP and JSON.
回答2:
I wouldn't use XML. XML still has it's uses but for this kind of setup the industry is making a shift towards JSON. The C# client will use some kind of JSON serialization method on the data you wish to send to the PHP service. The PHP app can then deserialize it and perform the appropriate actions. From there you write to your database like you would normally.
.Net comes with the JavascriptSerializer which works fine for basic situations but you should probably look into using JSON.Net as it provides a lot more flexibility.
PHP also has some built in JSON serialization stuff but I haven't used it so I can't speak to how well it works. However this article is linked to by JSON.org so it should give you a pretty good idea: http://gggeek.altervista.org/sw/article_20061113.html
来源:https://stackoverflow.com/questions/14531719/c-sharp-client-php-web-server-couchbase-db-how-to-pass-data-between-them