在免費的Pascal或Delphi應用程序中解析并序列化JSON-RPC2消息。 git存儲庫:https://github.com/r3code/pascal-jsonrpc-lite
受https://github.com/teambition/jsonrpc-lite的啟發。
JSON-RPC 2.0規格的實現
uses ujsonrpc;返回對像作為isuperObject克隆的形式內部json-object。
返回JSON字符串對象表示。
參數:
indent :{boolean}縮進的jsonescape :{布爾}逃脫特殊炭創建一個JSON-RPC 2.0請求對象,返回IJSONRPCMESSAGE對象。實現IJSONRPCMESSAGE。
參數:
id :{string | integer}method :{string}params :{ijsonrpcMessage}例子:
var requestObj: TJsonRpcMessage;
requestObj := TJsonRpcMessage.Request( ' 123 ' , ' update ' , SO( ' {list: [1, 2, 3]} ' ));
writeln(requestObj.asString);
// {
// jsonrpc: '2.0',
// id: '123',
// method: 'update',
// params: {list: [1, 2, 3]}
// } 創建一個JSON-RPC 2.0通知對象,返回IJSONRPCMESSAGE對象。
參數:
method :{string}params :{ijsonrpcMessage}例子:
var notificationObj: TJsonRpcMessage;
notificationObj := TJsonRpcMessage.notification( ' update ' , SO( ' {list: [1, 2, 3]} ' ));
writeln(notificationObj.asString);
// {
// jsonrpc: '2.0',
// method: 'update',
// params: {list: [1, 2, 3]}
// } 創建一個JSON-RPC 2.0成功響應對象,返回IJSONRPCMESSAGE對象。
參數:
id :{string | integer}result :{ijsonrpcMessage}例子:
var msg: TJsonRpcMessage;
msg := TJsonRpcMessage.success( ' 123 ' , ' OK ' );
writeln(msg.asString);
// {
// jsonrpc: '2.0',
// id: '123',
// result: 'OK',
// } 創建一個JSON-RPC 2.0錯誤響應對象,返回IJSONRPCMESSAGE對象。
參數:
id :{string | integer}error :{ijsonrpcmessage}使用tjsonrpcerror或它的兄弟姐妹例子:
var msg: TJsonRpcMessage;
msg := TJsonRpcMessage.Error( ' 123 ' , TJsonRpcError.Create(- 32000 , ' some error ' , ' blabla ' ));
writeln(msg.asString);
// {
// jsonrpc: '2.0',
// id: '123',
// error: {code: -32000, 'message': 'some error', data: 'blabla'},
// } 服用JSON-RPC 2.0有效載荷(字符串),並嘗試將其解析為JSON。如果成功,請確定它是什麼對象(響應,通知,成功,錯誤或無效),然後返回其類型並正確格式的對象。
參數:
s :{string}返回{ijsonrpcparsed}的對象。
顯示解析過程中檢測到的消息類型。類型:Jotinvalid,Jotrequest,Jotnotification,Jotsuccess,Joterror。
返回<{jsonrpcobjectType}之一。
返回存儲的裁判訪問ijsonrpcmessage。
實現接口ijsonrpcparsed。
創建一個tjsonrpcparsed實例。
參數:
objType :{tjsonrpcobjectType}消息格式類型payload :{ijsonrpcmessage}消息正文描述JSON-RPC 2.0錯誤對象。實現接口IJSONRPCMESSAGE。
創建一個TJSONRPCERROR實例。
參數:
code :{Integer}message :{string}data :{字符串| isuperObject | nil}可選示例:
var error: TJsonRpcError;
error = TJsonRpcError.Create(- 32651 , ' some error ' , ' some data ' );或者
var error: TJsonRpcError;
error = TJsonRpcError.Create(- 32651 , ' some error ' , SO( ' { a: 1, extra: "some data"} ' ));使用錯誤代碼-32600創建{tjsonrpcerror}對象。
參數:
data :{字符串| isuperObject | nil} - 額外數據使用錯誤代碼-32601創建{tjsonrpcerror}對象。
參數:
data :{字符串| isuperObject | nil} - 額外數據使用錯誤代碼-32602創建{tjsonrpcerror}對象。
參數:
data :{字符串| isuperObject | nil} - 額外數據使用錯誤代碼-32603創建{tjsonrpcerror}對象。
參數:
data :{字符串| isuperObject | nil} - 額外數據使用錯誤代碼-32700創建{tjsonrpcerror}對象。
參數:
data :{string} - 錯誤文本