如何序列化json,它具有标题和请求内的父头和请求。 [英] How to serialize json which has header and request inside parent header and request.

查看:107
本文介绍了如何序列化json,它具有标题和请求内的父头和请求。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网址: https://demo.abcd.cloud/icr/service? cmd = UPLOAD& format = json [ ^ ]





身体信息如下:

下面是我上传数据字符串的Text Visualizer。




{Header:{WorkstationId:DC3397CC-A2B6-C704-032E-0154EC02C7E8}

,请求:
{命令:添加,

添加:{

UploadType:1,

MsgRequest: {

标题:{

WorkstationId:DC3397CC-A2B6-C704-032E-0154EC02C7E8}


要求: {

SaleCodeExt:29CPQRSW,

WorkstationId:DC3397CC-A2B6-C704-032E-0154EC02C7E8,
AccountId:42E6B6C1-6CF2-0788-033B-0154EC06FD9B,

ShipAccountId:42E6B6C1-6CF2-0788-033B- 0154EC06FD9B,

TransactionDateTime:2016-05-31T11:36:43.264 + 0200,

TransactionType:1,

批准:true,

支付:真实,

编码:true,

打印:true,

验证:true,

SendOrderConfirmation:false,

CreateOrderConfirmation:false,

OrderDocTemplateId:null,

IncludeOrderConfirmationTickets:false,

PortfolioList:[{

WalletDeposit:0,

PortfolioGroup:PF1,

MediaList:[{

MediaStatus: 0,

MediaType:0,

MediaSerial:1,

EncodeDateTime:2016-05-31T11:36:43.264 + 0200,

EncodeFiscalDate:2016-05-31,

ExclusiveUse:true,

MediaCodeList:[{

MediaCode:1835EY41EP2PE8,

MediaCodeType:0

}]

}]

}],

TaxInInvoice:false,

SaleItemList:[{

ChargeToWallet:false,

数量:1,

UnitRawPrice:100,

ProductId:C683CF77-8C88-B8F9-0F95-0150050EDE6B,

UnitAmount:100,

TotalAmount:100,

TotalTax:0,

GroupTicketOption:1,

PerformanceTypeId:null,

TaxCalcType:1,

PresaleUnitAmount:0,

UnitTax:0,

SaleItemDetailList:[{

职位:1,

投资组合:PF1

}]

}],

PaymentList:[{

PaymentType:2,

PaymentStatus:2,

PaymentAmount:100

}]

}

}

}

}

}





系统答案:

{答案:{添加:{UploadId:E3EE30DF-0401-AB90-0244-015507753E3E}},标题:{Ver: 8.3.11.7\" , RequestCode: 上传, ETIME:62, SystemTimestamp: 2016-05-31T17:36:12.141 + 0200, 的StatusCode:200, 会话: EFEE7BA6BCE479477A7FE18294DDE203 }



目标是将数据上传到云上的系统。

虽然状态代码是200 (成功)错误即将到来的标题部分是i n侧



系统后台的错误信息是:

URL : https://demo.abcd.cloud/icr/service?cmd=UPLOAD&format=json[^]


Body message as bellow :
Below is my Text Visualizer of uploaddata string.


{Header: {WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8}
,Request:
{Command: Add,
Add: {
UploadType: 1,
MsgRequest: "{
Header: {
WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8 }
,
Request: {
SaleCodeExt: 29CPQRSW,
WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8,
AccountId: 42E6B6C1-6CF2-0788-033B-0154EC06FD9B,
ShipAccountId: 42E6B6C1-6CF2-0788-033B-0154EC06FD9B,
TransactionDateTime: 2016-05-31T11:36:43.264+0200 ,
TransactionType: 1,
Approved: true,
Paid: true,
Encoded: true,
Printed: true,
Validated: true,
SendOrderConfirmation: false,
CreateOrderConfirmation: false,
OrderDocTemplateId: null,
IncludeOrderConfirmationTickets: false,
PortfolioList: [{
WalletDeposit: 0,
PortfolioGroup: PF1 ,
MediaList: [{
MediaStatus: 0,
MediaType: 0,
MediaSerial: 1,
EncodeDateTime: 2016-05-31T11:36:43.264+0200 ,
EncodeFiscalDate: 2016-05-31 ,
ExclusiveUse: true,
MediaCodeList: [{
MediaCode: 1835EY41EP2PE8 ,
MediaCodeType: 0
}]
}]
}],
TaxInInvoice: false,
SaleItemList: [{
ChargeToWallet: false,
Quantity: 1,
UnitRawPrice: 100,
ProductId: C683CF77-8C88-B8F9-0F95-0150050EDE6B ,
UnitAmount: 100,
TotalAmount: 100,
TotalTax: 0,
GroupTicketOption: 1,
PerformanceTypeId: null,
TaxCalcType: 1,
PresaleUnitAmount: 0,
UnitTax: 0,
SaleItemDetailList: [{
Position: 1,
PortfolioGroup: PF1
}]
}],
PaymentList: [{
PaymentType: 2,
PaymentStatus: 2,
PaymentAmount: 100
}]
}
}"
}
}
}


System answer :
{"Answer":{"Add":{"UploadId":"E3EE30DF-0401-AB90-0244-015507753E3E"}},"Header":{"Ver":"8.3.11.7","RequestCode":"UPLOAD","ETime":62,"SystemTimestamp":"2016-05-31T17:36:12.141+0200","StatusCode":200,"Session":"EFEE7BA6BCE479477A7FE18294DDE203"}}

The target is to upload the data to the system which is on cloud.
Though status code is 200 (success) Error is coming header part which is inside.

Error message in back office of system is :

Expected a ',' or '}' at 514 [character 515 line 1]
{                            Header: {                             WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8     }, 





我尝试过其他例子,如果只有一个带有请求代码的标题正在后台执行而没有任何错误。



我尝试过:



以下我试过的代码:



System.Net.Http.HttpClient client = new System.Net.Http.HttpClient ();

client.BaseAddress = new System.Uri(SnAPIUrl);

client.DefaultRequestHeaders.Accept .Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(application / json));

System.Net.Http.HttpContent content1 = new StringContent(DATAUpload,UTF8Encoding.UTF8,application / json);



HttpResponseMessage messge = client.PostAsync(SnAPIUrl,content1).Result;



if(messge.IsSuccessStatusCode)

{

string result = messge.Content.ReadAsStringAsync()。结果;

Response.Write(结果);

//返回结果;

}



I have tried with other examples and if there is only single header with request code is executing without any error in back office.

What I have tried:

below code i have tried:

System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new System.Uri(SnAPIUrl);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.HttpContent content1 = new StringContent(DATAUpload,UTF8Encoding.UTF8,"application/json");

HttpResponseMessage messge = client.PostAsync(SnAPIUrl, content1).Result;

if (messge.IsSuccessStatusCode)
{
string result = messge.Content.ReadAsStringAsync().Result;
Response.Write(result);
//return result;
}

推荐答案

你需要在变量周围加上引号和字符串值:

You need to put quotation marks around the variables and string values:
{
	"Header": {
		"WorkstationId": "DC3397CC - A2B6 - C704 - 032E-0154 EC02C7E8"
	},
	"Request": {
		"Command": "Add",
		"Add": {
			"UploadType": 1,
			"MsgRequest": {
				"Header": {
					"WorkstationId": "DC3397CC - A2B6 - C704 - 032E-0154 EC02C7E8"
				},
etc.



查看系统答案。



参见JSON教程 [ ^ ]



这是一个可用于验证JSON的工具: JSONLint - The JSON验证器。 [ ^ ]

使用此用于测试我们的JSON数据以查看它是否正确的工具。


Look at the system answer.

See JSON Tutorial[^]

And this is one tool that can be used to validate JSON: JSONLint - The JSON Validator.[^]
Use this tool to test our JSON data to see if it is correct or not.


这篇关于如何序列化json,它具有标题和请求内的父头和请求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆