0
votes

I am trying to use json.net to produce a web service but I am a bit perplexed as to why < string > is showing in the dummy data

[WebMethod]
public string getCustomerInfo(string IVACode)
{
  var customerData = _dal.apertureAppstblCustomers.Where(a => a.IVACode == IVACode).ToList();

 var jsonstring = JsonConvert.SerializeObject(customerData);
        return jsonstring;
}

ie its starting like <string> and ending </string> how do i get it to display CustomerInformationinstead of string is it good practise to be naming the nodes?.

[{"id":"7aee450a-a9a7-4f19-83d3-467a3b8a39c0","IVACode":"IVA002","FirstName":"Peter","LastName":"Carson","AddressLine1":"Waters Edge Belfast","AddressLine2":null,"Town":"Belfast","County":"Down","PostCode":"BT99YXX","Telephone":null,"EmailAddress":"email","isActive":true,"authUserName":null,"authCreatedDate":null,"personalProgressValue":null,"contributionsToDate":null,"totalContributions":null,"totalArrears":50000.00,"totalPaid":null,"isDeleted":false,"deviceId":null,"deviceOs":null}]

2
If I understand it correctly when a webclient calls getCustomerInfo they get the content wrapped in <string></string> element? What is the base class of your webservice? If you inspect jsonstring with the debugger before it is returned, does it contain that <string></string> wrapper already? How do you test your method?rene
It is not a duplicate as I am using the json.net libary not the .net core funcitonallitycsharpdude77

2 Answers

0
votes

You will need to convert the serialized string back to your object and then consume it to show the relevant information.

Example below.

JsonConvert.DeserializeObject(jsonstring)

0
votes

You shouldn't get that in the serialized string but you can replace those tokens using Replace() string function like

jsonstring = jsonstring.Replace("<string>","").Replace("</string>","");