• Register
0 votes
353 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

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 27 views
27 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 Raphael Pacheco 4.9k points
0 votes
1 answer 46 views
46 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 Raphael Pacheco 4.9k points
0 votes
1 answer 275 views
275 views
Problem : I have spent over the 10 hours in finding the exception or the special character to find in the code but I am unable to find it. I have already checked every similar messages in here. I am facing below error: Syntaxerror: json.parse: unexpected character at line 1 ... my form after that I am sending all the inputs to the main.js to validate it. So, I am just looking for the third-eye.
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 301 views
301 views
Problem : I am facing error &ldquo;Expecting value: line 1 column 1 (char 0)&rdquo; when trying to decode the JSON.The URL I use for a API call works fine in a browser, but gives above error when done through the curl request. The error happens at the return simplejson.loads(response_json)
asked Jan 20 jwilliam 3.9k points
0 votes
1 answer 1.4K views
1.4K views
Problem : I am new to the Python, I am using Python-2.6 CGI scripts but facing following error in the server log while I was doing json.dumps(), Traceback (most recent call last): File "/etc/mongodb/server/cgi-bin/getstats.py", line 135, in <module> print json.dumps ... = datetime.datetime.strftime(now, '%Y-%m-%dT%H:%M:%S.%fZ') print json.dumps({'current_time': now}) // I guess this is the culprit
asked Nov 24, 2019 alecxe 7.5k points