• Register
0 votes
557 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 58 views
58 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 171 views
171 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
0 votes
1 answer 466 views
466 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 456 views
456 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, 2020 jwilliam 3.9k points
0 votes
1 answer 2.2K views
2.2K 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
0 votes
1 answer 21 views
0 votes
1 answer 204 views
204 views
Problem: I have fundamental knowledge on java , json and gson. I have below method: public static Object parseStringToObject(String json) {     String Object = json;     Gson gson = new Gson();     Object objects = gson.fromJson(object, Object. ... strange error message: "com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1"
asked Aug 4, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 649 views
649 views
Problem : Facing following ASP.Net error an asynchronous module or handler completed while an asynchronous operation was still pending.
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 114 views
114 views
Problem : I am new to ASP.Net and I have an ASP.Net application which runs correctly on my local development machine. But when I try to run this application online, it shows me following error Format of the initialization string does not conform to specification starting at index 0 I don’t have any clue about this error. Does anybody have any idea regarding solution on this error?
asked Nov 25, 2019 alecxe 7.5k points
0 votes
1 answer 14 views
14 views
I have a hash of words and respective frequencies, that I want to order by frequency. Sorted Dictionary orders by key, not value. Some resort to a custom class, but is there a cleaner way?
asked Aug 31, 2020 Sofi55 1.1k points