提问人:Winter Wind 提问时间:9/5/2023 最后编辑:Nafis IslamWinter Wind 更新时间:9/14/2023 访问量:49
合并 2 个 json 值
Merging 2 json values
问:
我有一个JSON正文
{
"id": "1581fbd2-c045-4162-9f4c-ddbca6a88d61",
"content": "VONP//content in base64",
"title": "ProfileImage",
"type": "image/jpeg",
"created": "2023-08-03T18:55:46.736405+03:00"
}
我想像这样待在里面type
content
{
"content": "image/jpeg//content in base64",
"type": "image/jpeg"
}
附加代码:
我有一个json的模型
public class MediaModelResponse
{
public Guid Id { get; set; }
public byte[] Content { get; set; }
public string Title { get; set; }
public string Type { get; set; }
public DateTime Created { get; set; }
}
无法找出正确的方法
答:
0赞
Richard Housham
9/14/2023
#1
让我们试着把一些代码放在一起来完成这个任务。
首先,让我们假设我们在这个变量中有我们的模型...... 然后把文章发布。在 C# 中将字符串转换为字节数组 在 C# 数组之前 给你这样的东西。
var MyMediaResponse = new MediaModelResponse();
//populate MyMediaResponse
byte[] TypeBytes = Encoding.ASCII.GetBytes(MyMediaResponse.Type);
var newContent = MyMediaResponse.Content.Prepend(TypeBytes);
var obj = new
{
Id = MyMediaResponse.Id ,
Content = newContent ,
Title = MyMediaResponse.Title,
Created = MyMediaResponse.Created
};
var jsonString = JsonSerializer.Serialize(obj);
这样的事情应该有效(理论上)
评论
content
type