-2

I'm using .NET 6 and an API using the Entity Framework. Scenario, I receive Soup API and then create new API, output is json result when I test I get correct results, but after I publish the project on Azure the API is not show out I want.

[HttpGet("[action]")]
        public IActionResult GetExamService(string id, string Examcodes, string codes)
        {
            try
            {
                ExamServiceClient exam = new();
                ExamDetailsStructure abilitiesExam = new();
                ExamResults.PersonNameBody ApplicantName = new();
                var response = exam.GetExamResultAsync(id, Examcodes, codes).Result.Item;
                if (!response.GetType().ToString().Equals(abilitiesExam.GetType().ToString()))
                {
                    throw new NullReferenceException("no data found " + id);
                }
                abilitiesExam = (ExamDetailsStructure)response;
                ApplicantName = (QyiasExamResults.PersonNameBody)abilitiesExam.ApplicantName.Item;

                ExamDetailsBody ExamDetailsBody = new()
                {
                    ExamSpecialty = abilitiesExam.ExamSpecialty.ToString() ?? "",
                    ExamResultTypeEnSpecified = abilitiesExam.ExamResult.ExamResultTypeEnSpecified.ToString() ?? "",
                };
                return Ok(new
                {
                    ExamDetailsBody = ExamDetailsBody
                });
            }
            catch (NullReferenceException ex)
            {
                ErrorResponse error = new(ex.Message, StatusCodes.Status404NotFound);
                return StatusCode((int)HttpStatusCode.NotFound, error);
            }
            catch
            {
                ErrorResponse error = new("internal server error", StatusCodes.Status500InternalServerError);
                return StatusCode((int)HttpStatusCode.InternalServerError, error);
            }
        }

JSON Output

the Azure output this results:

HTML Output

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81
sp 4_4
  • 122
  • 6
  • 2
    What do you mean by "I want to show that in HTML"? Please read https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/ and put *much* more information into your answer. As far as I can see, the only difference is whether the characters are escaped or not, which should be irrelevant - they're equivalent in JSON. – Jon Skeet Oct 02 '22 at 06:21
  • Might you please [edit] your question to include your JSON as **text** rather than as a screenshot? On stack overflow images should not be used for textual content, see [*Discourage screenshots of code and/or errors*](https://meta.stackoverflow.com/a/307500) and [*Why not upload images of code on SO when asking a question*](https://meta.stackoverflow.com/a/285557) for why. For instructions on formatting see *[How do I format my code blocks?](https://meta.stackexchange.com/q/22186)*. A [mcve] showing what you have tried that did not work would maximize your chances of getting help. See [ask]. – dbc Oct 02 '22 at 06:23
  • That being said, assuming you are using .NET Core 3.1 or later, if your only problem is that you would prefer to disable optional escaping of non-ASCII characters in JSON text, see [dotnet core System.Text.Json unescape unicode string](https://stackoverflow.com/q/58003293) and also [Issues with System.Text.Json serializing Unicode characters (like emojis)](https://stackoverflow.com/q/58738258). – dbc Oct 02 '22 at 06:24
  • Why do you want to see that data in encoded html? it is json. What you are seeing is correct encoding for those characters – Chris Schaller Oct 04 '22 at 14:47
  • You need to change the content type of the response from text/HTML to Application/json – Chris Schaller Oct 04 '22 at 14:54
  • or in your consuming code, html decode the text first. – Chris Schaller Oct 04 '22 at 14:55

1 Answers1

0

This solved my problem. I used JSON Serializer NewtonsoftJson

    //JSON Serializer
builder.Services.AddControllers().AddNewtonsoftJson(options =>
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
    .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

for more details about package Microsoft Ignite and donwload from nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson

sp 4_4
  • 122
  • 6