Click here to Skip to main content
15,883,870 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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 :
C#
Expected a ',' or '}' at 514 [character 515 line 1]
{                            Header: {                             WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8     }, 


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;
}
Posted
Updated 2-Jun-16 2:45am
v2

1 solution

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

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.
 
Share this answer
 
v2
Comments
nipen.mehta 1-Jun-16 0:33am    
@ George : I am using C# asp.net and posting the above mentioned json string. yes i agree with you that json require "" when it post data, that will handle by default by the code which i have tried above. In simple header and request I am not facing any problem in post data. Here I have header inside header.
I am looking for the solution where i can serialize the complete json before I execute PostAsync;
HttpResponseMessage messge = client.PostAsync(SnAPIUrl, content1).Result;
George Jonsson 1-Jun-16 5:39am    
Do you mean serialize a C# object to JSON?
Your statements are confusing because the error code you have shown in the question is because of the lack of quotation marks (") and the JSON code you show is without them.
nipen.mehta 1-Jun-16 6:03am    
Yes, serialize from C# to JSON. The code I have posted above is Text visualizer of DATAUpload variable. so it will not have "".

<pre lang="C#">System.Net.Http.HttpContent content1 = new StringContent(DATAUpload,UTF8Encoding.UTF8,"application/json");</pre>

C#.Net will do post from below code.

<pre lang="C#">HttpResponseMessage messge = client.PostAsync(SnAPIUrl, content1).Result;</pre>

And I am receiving Answer too as expected :

{"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"}}

-- I am receiving the answer but transaction is failed in back office because of format.

The error is showing in backoffice system where the above post is happening.
I have checked with other request which has one header and request the same code is working properly and status success in backoffice too. I want to know how can i serialize this insider header and request which is giving me error in backoffice. It should have done by itself from C# only same like other normal request. But is not happening.
George Jonsson 1-Jun-16 10:46am    
Well, that is not easy to know for anyone but you.
You say you get an error sending your JSON data, and the JSON structure you show is not in a valid format, so what am I supposed to think?
Have you tried to validate the true JSON output in the online tool I linked?
Just convert the data to a string or save to a file and then paste it into the validator. If you do that you might find the problem.
And why don't you ask the back office guys what is wrong with the format?

As you don't show the true JSON data it is difficult to give more help. This is weird though.
MsgRequest: "{
Header: {
What is the quotation mark doing there?
nipen.mehta 2-Jun-16 1:23am    
Yes I have tried that link and validate json already. over there i have to put "" for sure because it will accept only tipical format of json. If you know about postman tool
[^] in that we don't require to put "". If I am doing the post request with postman it is posting data successfully in backoffice. Same way C#.Net also handle "" when I pass format <pre lang="XML">application/json</pre>

Please check here :
<pre lang="C#">System.Net.Http.HttpContent content1 = new StringContent(DATAUpload,UTF8Encoding.UTF8,"application/json");

HttpResponseMessage messge = client.PostAsync(SnAPIUrl, content1).Result;</pre>
I am formatting the content of DATAUpload into json and then with HttpResponseMessage I am posting result to specific URL. So there is no worry of "" from my client side (Asp.Net page)

MsgRequest: "{
Header: {

and in bottom of json also
PaymentStatus: 2,
PaymentAmount: 100
}]
}
}"
}
}
}

That I handle in C# code with regular expression.
@"{Header: {WorkstationId: DC3397CC-A2B6-C704-032E-0154EC02C7E8}
,Request:{Command: Add,
Add: {
UploadType: 1,
MsgRequest: ""{
Header: {
.......
.....
}
}""
}
}
}";

If I have simple header and request then no issue. Even C#.Net is not giving me any error when I execute this code which i have posted. If you see, I have also posted Answer in bold format, this is coming in result.
<pre lang="C#">string result = messge.Content.ReadAsStringAsync().Result;</pre>

Error is coming in back office and data is not uploading and giving me format error issue. And I am sure this error is at insider header only. because when i try to some format change its giving me error there only. Can you please help me with any other example reference which has this kind of format of double header and request.I really appreciate your time and effort. Thank you very much. This is really choking issue for me, need help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900