0

I'm getting the following exception:

Newtonsoft.Json.JsonReaderException in Newtonsoft.Json.dll ("Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1."). Exception thrown: 'Newtonsoft.Json.JsonReaderException' in Newtonsoft.Json.dll ("Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.

Here is the code:

JObject data = JObject.Parse(verigetir(veri.getir(), "cari_ip_alma.php"));

public string verigetir(string veri, string sayfa)
{
    string postData;

    WebRequest request = WebRequest.Create(server + sayfa);
    request.Method = "POST";
    postData = veri;
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    WebResponse response = request.GetResponse();
    dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);

    return reader.ReadToEnd();

    reader.Close();
    dataStream.Close();
    response.Close();
}

class parametreOlustur
{
    public string data;

    public void birlestir(string a, string b)
    {
        data += "&" + a + "=" + b;
    }

    public string getir()
    {
        return data;
    }
}

PHP Code :

https://shrib.com/?v=md#iT73qB_Lr250Uoh8CZbk

if i'm change php codes $row= $sql->fetchAll(PDO::FETCH_ASSOC) fetchAll to Fetch , program is working but getting first data.

Eagle
  • 11
  • 1
  • 2
  • Formatting, Inlined the source code example – Scott Smith Apr 19 '18 at 19:09
  • 1
    Can you include the input data being parsed? That may be where the problem is. Also, I notice that you're returning from `verigetir` before closing your streams. You should be getting a build warning on that... – Scott Smith Apr 19 '18 at 19:11
  • Just i want to get all mssql table data – Eagle Apr 20 '18 at 08:33
  • 1
    Your JSON root container is an array not an object. See [Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path](https://stackoverflow.com/q/34690581) for how to fix. If you don't know in advance if your JSON represents an object or an array, see [JSON.NET: Why Use JToken--ever?](https://stackoverflow.com/q/38211719/3744182) for how to fix. To give you any specific help we need an [mcve] showing the JSON you are trying to parse. – dbc Apr 21 '18 at 19:18
  • 1
    Unrelated to the actual question, you need to learn to use the [`using`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement) statement to dispose of disposables like `reader`, `dataStream` and `response`. – dbc Apr 21 '18 at 19:26
  • I fix my problem if rows bigger than 1 Jobject Doesn't working , i'm chagne Jobject to Jarray and my problem has fixed , thanks guys :) – Eagle Apr 24 '18 at 06:21

0 Answers0