JSON

֪ʶѧϰ֮Json-RPC

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-04-27 09:04 ÎÒÒªÆÀÂÛ( )

֪ʶѧϰ֮Json-RPCJSON-RPC¼¼Êõ JSON-RPCÊÇÒ»¸öÎÞ״̬ÇÒÇáÁ¿¼¶µÄÔ¶³Ì¹ý³Ìµ÷ÓÃ(RPC)ЭÒé¡£ ±¾¹æ·¶Ö÷Òª¶¨ÒåÁËһЩÊý¾Ý½á¹¹¼°ÆäÏà¹ØµÄ´¦Àí¹æÔò¡£ËüÔÊÐíÔËÐÐÔÚ»ùÓÚsocket,httpµÈÖî¶à²»Í¬ÏûÏ¢´«Êä»·¾³µÄͬһ½ø³ÌÖС£ ЭÒéÃèÊödata sent to Server { "method": "s

֪ʶѧϰ֮Json-RPC JSON-RPC¼¼Êõ

JSON-RPCÊÇÒ»¸öÎÞ״̬ÇÒÇáÁ¿¼¶µÄÔ¶³Ì¹ý³Ìµ÷ÓÃ(RPC)ЭÒé¡£ ±¾¹æ·¶Ö÷Òª¶¨ÒåÁËһЩÊý¾Ý½á¹¹¼°ÆäÏà¹ØµÄ´¦Àí¹æÔò¡£ËüÔÊÐíÔËÐÐÔÚ»ùÓÚsocket,httpµÈÖî¶à²»Í¬ÏûÏ¢´«Êä»·¾³µÄͬһ½ø³ÌÖС£

ЭÒéÃèÊö data sent to Server

{ "method": "sayHello", "params": ["Hello JSON-RPC"], "id": 1}
²ÎÊý½éÉÜ:<br/>
method£º µ÷Óõķ½·¨Ãû
params£º ·½·¨´«ÈëµÄ²ÎÊý£¬ÈôÎÞ²ÎÊýÔò´«Èë []
id £º µ÷Óñêʶ·û£¬ÓÃÓÚ±êʾһ´ÎÔ¶³Ìµ÷Óùý³Ì£»Òѽ¨Á¢¿Í»§¶ËµÄΨһ±êʶid£¬Öµ±ØÐë°üº¬Ò»¸ö×Ö·û´®¡¢ÊýÖµ»òNULL¿ÕÖµ¡£Èç¹û²»°üº¬¸Ã³ÉÔ±Ôò±»È϶¨ÎªÊÇÒ»¸ö֪ͨ¡£

Note
·þÎñ¶Ë±ØÐë»Ø´ðÏàͬµÄÖµÈç¹û°üº¬ÔÚÏìÓ¦¶ÔÏó¡£ Õâ¸ö³ÉÔ±ÓÃÀ´Á½¸ö¶ÔÏóÖ®¼äµÄ¹ØÁªÉÏÏÂÎÄ¡£

[1] ÔÚÇëÇó¶ÔÏóÖв»½¨ÒéʹÓÃNULL×÷ΪidÖµ£¬ÒòΪ¸Ã¹æ·¶½«Ê¹ÓÿÕÖµÈ϶¨ÎªÎ´ÖªidµÄÇëÇó¡£ÁíÍ⣬ÓÉÓÚJSON-RPC 1.0 µÄ֪ͨʹÓÃÁË¿ÕÖµ£¬Õâ¿ÉÄÜÒýÆð´¦ÀíÉϵĻìÏý¡£

[2] ʹÓÃСÊýÊDz»È·¶¨ÐԵģ¬ÒòΪÐí¶àÊ®½øÖÆСÊý²»Äܾ«×¼µÄ±í´ïΪ¶þ½øÖÆСÊý¡£

data sent to Client

{ "result":"Hello JSON-RPC","error",null,"id":1}
²ÎÊý½éÉÜ:<br/>
result: ·½·¨·µ»ØÖµ£¬ÈôÎÞ·µ»ØÖµ£¬Ôò·µ»Ønull¡£Èôµ÷ÓôíÎ󣬷µ»Ønull¡£
error £ºµ÷ÓÃʱ´íÎó£¬ÎÞ´íÎó·µ»Ønull¡£
¸Ã³ÉÔ±ÔÚʧ°ÜÊDZØÐë°üº¬¡£
µ±Ã»ÓÐÒýÆð´íÎóµÄʱ±ØÐë²»°üº¬¸Ã³ÉÔ±¡£
id: µ÷Óñêʶ·û£¬Óëµ÷Ó÷½´«ÈëµÄ±êʶ·ûÒ»Ö¡£
¸Ã³ÉÔ±Öµ±ØÐëÓÚÇëÇó¶ÔÏóÖеÄid³ÉÔ±ÖµÒ»Ö¡£
ÈôÔÚ¼ì²éÇëÇó¶ÔÏóidʱ´íÎó£¨ÀýÈç²ÎÊý´íÎó»òÎÞЧÇëÇ󣩣¬Ôò¸ÃÖµ±ØÐëΪ¿ÕÖµ¡£

֪ͨģʽ

ûÓаüº¬¡°id¡±³ÉÔ±µÄÇëÇó¶ÔÏóΪ֪ͨ

example

ËùÓж¼ÎªÍ¨ÖªµÄrpcÅúÁ¿µ÷ÓÃ:

--> [
{"jsonrpc": "2.0", "method": "notify_sum", "params": [1,2,4]},
{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}
]
<-- //Nothing is returned for all notification batches

rpcµ÷ÓÃÈç¹û´æÔÚ²ÎÊýÔò±ØÐëΪ»ù±¾ÀàÐÍ»ò½á¹¹»¯ÀàÐ͵IJÎÊýÖµ£¬ÒªÃ´ÎªË÷ÒýÊý×飬ҪôΪ¹ØÁªÊý×é¶ÔÏó¡£

Ë÷Òý£º²ÎÊý±ØÐëΪÊý×飬²¢°üº¬Óë·þÎñ¶ËÔ¤ÆÚ˳ÐòÒ»ÖµIJÎÊýÖµ¡£

¹ØÁªÃû³Æ£º²ÎÊý±ØÐëΪ¶ÔÏ󣬲¢°üº¬Óë·þÎñ¶ËÏàÆ¥ÅäµÄ²ÎÊý³ÉÔ±Ãû³Æ¡£Ã»ÓÐÔÚÔ¤ÆÚÖеijÉÔ±Ãû³Æ¿ÉÄÜ»áÒýÆð´íÎó¡£Ãû³Æ±ØÐëÍêÈ«Æ¥Å䣬°üÀ¨·½·¨µÄÔ¤ÆÚ²ÎÊýÃûÒÔ¼°´óСд¡£

error object

{"code":"", message:"","data":""}

code:ʹÓÃÊýÖµ±íʾ¸ÃÒì³£µÄ´íÎóÀàÐÍ¡£ ±ØÐëΪÕûÊý¡£
message:¶Ô¸Ã´íÎóµÄ¼òµ¥ÃèÊö×Ö·û´®¡£ ¸ÃÃèÊöÓ¦¾¡Á¿ÏÞ¶¨ÔÚ¼ò¶ÌµÄÒ»¾ä»°¡£
data:°üº¬¹ØÓÚ´íÎ󸽼ÓÐÅÏ¢µÄ»ù±¾ÀàÐÍ»ò½á¹¹»¯ÀàÐÍ¡£¸Ã³ÉÔ±¿ÉºöÂÔ¡£ ¸Ã³ÉÔ±ÖµÓÉ·þÎñ¶Ë¶¨Ò壨ÀýÈçÏêϸµÄ´íÎóÐÅÏ¢£¬Ç¶Ì׵ĴíÎóµÈ£©¡£

×ܽá

json-rpcÊÇÒ»Öַdz£ÇáÁ¿¼¶µÄ¿çÓïÑÔÔ¶³Ìµ÷ÓÃЭÒ飬ʵÏÖ¼°Ê¹Óüòµ¥¡£½öÐ輸ʮÐдúÂ룬¼´¿ÉʵÏÖÒ»¸öÔ¶³Ìµ÷ÓõĿͻ§¶Ë£¬·½±ãÓïÑÔÀ©Õ¹¿Í»§¶ËµÄʵÏÖ¡£

ÖÁÓÚ WEB¿ª·¢ÖУ¬Ê¹ÓÃJSON-RPCºÃ£¬»¹ÊÇRESTful APIºÃ£¿
¿ÉÒÔÒƲ½ÕâÀï

²Î¿¼ÎÄÕÂ

1.

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Qt ѧϰ֮· 2£¨63£©£ºÊ¹Óà QJson ´¦Àí JSON

    Qt ѧϰ֮· 2£¨63£©£ºÊ¹Óà QJson ´¦Àí JSON

    2017-04-19 08:03

  • Json for Java APIѧϰ

    Json for Java APIѧϰ

    2017-04-16 13:03

  • ±ðÑùJAVAѧϰ£¨Ò»£©»ù´¡ÖªÊ¶

    ±ðÑùJAVAѧϰ£¨Ò»£©»ù´¡ÖªÊ¶

    2017-04-03 10:04

  • JSON-RPC.NETµ÷ÓÃʾÀý

    JSON-RPC.NETµ÷ÓÃʾÀý

    2017-03-27 14:01

ÍøÓѵãÆÀ