如何将两个json对象组合成jsonobject [英] How to combined two json object into jsonobject
问题描述
我有两个方法。一个方法用于通过正文传递数据,我可以通过json格式传递正文,还有另一种方法通过json格式的头传递数据,但我需要结合两个json对单个jsonobject格式的响应怎么能这样做。很多例子我看到它对我不起作用。请帮助我。
正文数据代码
[Httppost]
[路线( api /帐户/登录)]
public async 任务< getbasecustomerresponse>登录([来自正文] LoginRequest请求)
{
return 响应;
}
标题数据代码:
private HttpWebRequest CreateRequestObject( string ServiceURL)
{
HttpWebRequest request = null ;
尝试
{
var _authkey = configurationManger.APPSetting [< span class =code-string> userkey];
request =(HttpWebRequest)WebRequest.Create(ServiceURL)
request.Method = Post 跨度>;
request.ContentType = Application / Json;
request.Headers.Add( AuthKey,_ authkey);
}
catch (例外情况)
{
}
返回请求
}
请帮帮我,
谢谢你。
我是什么尝试过:
i有两个方法。一个方法用于通过身体传递数据我可以在json中传递身体格式以及另一种通过json格式的头传递数据的方法,但是我需要将json响应结合到单个jsonobject格式中如何才能做到这一点。我看到它的例子很多我不适用于我。请帮助我。
我想看看这个。它也有一个例子
合并JSON [ ^ ]
i have two methods.one method is used for passing the data through the body at the time i can possible to pass the body in json format and also another method for passing the data through header in json format but i need to combine both json response to single jsonobject format how can do this.many of examples i seen it's not worked for me.please help me.
Body data code
[Httppost]
[Route("api/Account/Login")]
public async task<getbasecustomerresponse> Login([From body]LoginRequest request)
{
return response;
}
Header data code:
private HttpWebRequest CreateRequestObject(string ServiceURL)
{
HttpWebRequest request=null;
try
{
var _authkey=configurationManger.APPSetting["userkey"];
request=(HttpWebRequest)WebRequest.Create(ServiceURL)
request.Method="Post";
request.ContentType="Application/Json";
request.Headers.Add("AuthKey",_authkey);
}
catch(Exception ex)
{
}
return request
}
please help me,
Thank u.
What I have tried:
i have two methods.one method is used for passing the data through the body at the time i can possible to pass the body in json format and also another method for passing the data through header in json format but i need to combine both json response to single jsonobject format how can do this.many of examples i seen it's not worked for me.please help me.
I would have a look at this. It has an example too
Merging JSON[^]
这篇关于如何将两个json对象组合成jsonobject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!