• Register
0 votes
724 views

Problem :

Currently I am facing some issues. I am trying to  use C# with Json.NET. The problem is that I always get following error:

{"Unexpected character encountered while parsing value: e. Path '', line 0, position 0."}

So the way I amm using Json.NET is as below. I am having a Class which should be saved. The class looks like following:

public class mystats
{
    public string mytime { get; set; }
    public string myvalue { get; set; }
}
public class MyViewerStatsFormat
{
    public List<stats> myviewerstats { get; set; }
    public String myversion { get; set; }
    public MyViewerStatsFormat(bool mychk)
    {
        this.myviewerstats = new List<stats>();
    }
}

One of the object of this class will be filled and saved with following:

 File.WriteAllText(tmpfile, JsonConvert.SerializeObject(current), Encoding.UTF8);

The saving part of the code works fine and the file exists and is filled. After that the file should be read back into the class with following code:

 try 
{ 
    MyViewerStatsFormat mycurrent = JsonConvert.DeserializeObject<MyViewerStatsFormat>(tmpfile);
    //otherstuff        
}
catch(Exception ex)
{
    //error loging stuff
}

Now on this line comes up the exception as follows:

{"Unexpected character encountered while parsing value: e. Path '', line 0, position 0."}

Does anyone have any solution on it?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I had faced the same problem in the past in my case the issue came as my application needed the authentication, then it assigns the annotation [AllowAnonymous] and it worked.

Please find below solution:

[AllowAnonymous]
public async Task <IList <IServic >> GetServices () {
  }
9 7 4
38,600 points

Related questions

0 votes
1 answer 95 views
95 views
Problem: I have a number of "test" projects in my visual studio solution that I have already excluded from building when I try to rebuild a solution. On the other hand if I try to rebuild a solution then I still see my those projects in my output window with below ... . Is there any way known to you to exclude that message from getting displayed in my output window if I try to rebuild my solution?
asked Aug 14, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 3 views
3 views
Problem: I am stuck now and need some suggestions > A circular reference was detected while serializing an object of type
asked 4 days ago ummeshani 10.8k points
0 votes
1 answer 5 views
5 views
Problem: Can anyone tell me the solution to this problem > Confirm that the path in the <import> declaration is correct, and that the file exists on disk.
asked Apr 23 ummeshani 10.8k points
1 vote
1 answer 9 views
9 views
Problem : I have the following problem, I use Visual Studio 2013, I created a system where basic operations (search, delete, enter) are done, bound to a database created in SQL SERVER 2008. The problem occurs to me when you tried to enter a new photo ... error is specifically in this part: FileStream stream = new FileStream(txtexaminar.Text, FileMode.Open,FileAccess.Read); How can I solve this!
asked Apr 7 Sabbir Hossain 14.6k points
0 votes
1 answer 3 views
3 views
Problem: If you could lead me in the right way, I would appreciate it.
asked Apr 13 zayed1 61.8k points
0 votes
1 answer 26 views
26 views
Problem: In a React app component that handles Facebook-like content feeds, I am running into an error: Feed.js:94 undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0 Thanks
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 30 views
30 views
Problem: I am getting the error SyntaxError: Unexpected token C in JSON at position 0. I am also assuming that the error is related to the request.
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 15 views
15 views
Problem: In a React app component that handles Facebook-like content feeds, I am running into an error: Feed.js:94 undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 19 views
19 views
Problem: Only at the checkout and on individual product pages I am getting the following error in the console log: Uncaught SyntaxError: Unexpected token u in JSON at position 0
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 339 views
339 views
Problem: Recently I have joined the angular2 project. But now I am stuck with below listed errors. The errors occurred if I tried to send my JSON objects to my backend. It may be due a parsing of my JSON objects. I am very new to angualar so unable to find ... (core.umd.js:3971) at ZoneDelegate.invokeTask (zone.js:274) at Zone.runTask (zone.js:151) at XMLHttpRequest.ZoneTask.invoke (zone.js:345)
asked Aug 5, 2020 Raphael Pacheco 4.9k points