本帖最后由 James.Lv 于 2021-9-29 11:42 编辑
在报表设计中,除了使用数据库的数据展示之外,有时我们也需要去请求一些API接口的JSON数据。默认我们支持的是GET请求,有些接口呢我们也需要使用POST请求,本贴就来介绍如何使用JSONAPI数据源。
具体实现方法:
一、GET请求方式
GET请求方式比较简单,具体可以参考文档:
https://help.grapecity.com.cn/pa ... tion?pageId=5968536
二、POST请求方式
1.桌面端设计器
1.1创建报表,添加数据源,使用json数据源,使用链接字符串。
1.2 链接字符串内容解析- method:代表请求方式
- headers:代表请求头信息
- body:代表POST请求报文体
- jsondoc:代表请求的URL
- schemadata:代表JSON数据的schema信息(可选)
复制代码 示例链接字符串- method=POST;headers={"Content-Type": "application/json"};body={"dataSetDoc":{"name":"楼盘数据","query":{"dataSources":[{"id":"0e08eb20-b984-4ca0-ab28-6d85b515d6ec","name":"项目运营","fileName":null,"provider":null,"useAdvancedConfig":false,"connectionString":null,"mappingConfigs":null,"useUserContext":false,"useMultiTenant":false,"isExtracted":false}],"parameters":[],"commandText":"SELECT [楼号],[数值] FROM [楼盘数据] ","commandType":"Sql","commandModel":{"firstTable":{"id":"715464","tableType":"NativeTable","tableName":"楼盘数据(0e08eb20-b984-4ca0-ab28-6d85b515d6ec)","sql":null,"dataSourceId":"0e08eb20-b984-4ca0-ab28-6d85b515d6ec","unionType":"none","unionMap":null,"filters":[],"sQlExpressions":[],"tables":[]},"joinRelations":[]}},"fields":[{"table":"楼盘数据(0e08eb20-b984-4ca0-ab28-6d85b515d6ec)","column":"楼号","alias":"","description":"","dataType":"String","format":"","fieldType":"Normal","aggregation":null,"rawType":null,"msDescription":""},{"table":"楼盘数据(0e08eb20-b984-4ca0-ab28-6d85b515d6ec)","column":"数值","alias":"","description":"","dataType":"Number","format":"f2","fieldType":"Normal","aggregation":null,"rawType":null,"msDescription":""}],"groupFields":[],"customSqlTables":[],"filterExpressions":null,"filterConditions":{"conditionType":0,"conditionItems":[],"type":null,"table":null,"column":null,"expression":null,"operator":null,"value":null,"valueType":null,"targetType":null},"indexed":true,"tagIds":null,"comment":null,"incrementalUpdateSetting":null},"parameters":[],"uriParams":[]};jsondoc=http://localhost:51980/api/datasetmanagement/preview?ignoreusercontext=false&rowcount=100&token=959bcde9cde7eb36aa691e34c2f453b4af21d4541cb7fb98514c4583f38a2984
复制代码 1.3 然后就可以基于这个数据源进行数据集和报表设计
2.web端设计器
2.1 创建报表,添加数据源,使用json数据源,使用链接字符串。
链接字符串格式跟桌面端一致。之后的设计也跟桌面端设计方式一致
|