Comments (4)
[JsonPropertyName],因为KeyValue序列化也是使用system.text.json
from webapiclient.
如果我还有Form 的某个字段为 json 文本的离谱需求有相应的特性可以用来标注吗
from webapiclient.
from webapiclient.
跟着源码debug了一遍,大概看到是先通过System.Text.Json
转换为Josn然后再转为请求参数,所以用了个转换器来折中的解决这个问题
实体类
/// <summary>
/// AccessToken输入参数
/// </summary>
public class AccessTokenInput
{
/// <summary>
/// 客户端ID
/// </summary>
[JsonPropertyName("client_id")]
public string ClientId { get; set; }
/// <summary>
/// 访问内容
/// </summary>
[JsonConverter(typeof(ObjectToStringConverter))]
public ChatContent Content { get; set; }
}
public record ChatContent(string content)
转换器
public class ObjectToStringConverter : JsonConverter<object>
{
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert.IsClass;
}
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var serialize = JsonSerializer.Deserialize<string>(ref reader, options);
return JsonSerializer.Deserialize(serialize, typeToConvert, options);
}
public override void Write(
Utf8JsonWriter writer,
object objectToWrite,
JsonSerializerOptions options)
{
writer.WriteStringValue(JsonSerializer.Serialize(objectToWrite, options));
}
}
声明接口
Task<string> SendMsg([FormContent] AccessTokenInput input);
from webapiclient.
Related Issues (20)
- 如何使用?
- 如何设置请求http版本? HOT 2
- 禁用日志 HOT 1
- 使用Prism TryIoc 依赖注入环境下, 如何注册IHttpApi 的生成实例方法 HOT 1
- 特性JsonTent问题 HOT 1
- JsonContent 特性问题 HOT 1
- JsonContent 特性问题 HOT 2
- The relative expiration value must be positive. (Parameter 'AbsoluteExpirationRelativeToNow') Actual value was -00:00:10. HOT 1
- 是否支持失败重试+自定义重试策略 HOT 5
- 是否考虑支持接口转发的功能 HOT 5
- .net 7.0 Console程序怎么使用该组件? HOT 2
- .net 7.0的Console程序提示不支持将ContentType为 text/html 的内容转换为对象 HOT 3
- 生成上传文件代理时,找不到FileParameter参数。
- TimeOut action属性和Param属性 设置之后都不起作用 无论设置多少都是60秒超时 HOT 2
- WriteLog方法BUG。 HOT 2
- 如何处理超时异常 HOT 2
- 请问 HttpApiClient.Create<T>() 还支持吗? HOT 1
- 请求执行时出现SocketException,是否考虑将HttpContext也抛出
- 支持添加自定义请求头吗? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webapiclient.