Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Newtonsoft.Json: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray

Hi I am passing the below string in my code in line var json = JObject.Parse(jStr); and I get the error as

System.Private.CoreLib: Exception while executing function: Function1.
Newtonsoft.Json: Error reading JObject from JsonReader. Current
JsonReader item is not an object: StartArray.

Can someone please explain me how should I fix this. Is it because it is an array kind? At the end my passed string will be an array. how can I fix this?. here is the sample string(one object from the array) which I am passing in above line

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  {
    "_id": "_AUQ9",
    "im:SiceErrors": {
      "errors": [
        {
          "_id": "O9UQ9_0",
          "ErrorMessage": "Uype",          
          "Parameter": "r:type",
          "ParameterValue": "[\n  \"~:bbl:P924\",\n  \"~:corer:ag\"\n]",
          "RefObjectParameter": "type_key",
          "Project": "NPOS+1"
        }
      ]
    },
    "cullad-tag:Cject": "P|GT",
    "bbl:P1014": "PIGT",
    "cullad-tag:MoomosBaseObjectDescription": "Gate Valve",
    "bbl:P3935": "Gve",
    "cullad-tag:CreateDate": "15.10.2021",
    "cullad-tag:MoomosDescription": "P2",
    "cullad-tag:MoomosUID": "A49",
    "bbl:011772": "UQ9",
    "cullad-tag:Description": "P2",
    "cullad-tag:Discipline": "U",
    "bbl:P101001445": "bbl:P163",
    "cullad-tag:FLabel": "FFeed",
    "bbl:P1094": "pd:P1299",   
    "bbl:P10791": "V",
    "cullad-tag:FutureTag": "No",
    "cullad-tag:IndexType": "MV",
    "bbl:P138": "bbl:P1563",
    "cullad-tag:IsTopTag": "No",
    "bbl:P7": "No",
    "cullad-tag:MountedOn": "F-18UD800",
    "bbl:P4024": "F-18800",   
    "bbl:P1834": "pd:P1094",    
    "bbl:P1803": "8120",
    "cullad-tag:SubProjectCategory": "Feed",
    "cullad-tag:SubProjectName": "SUB",
    "cullad-tag:System": "18",
    "bbl:P01660": "bbl:P15326",
    "cullad-tag:TagNumber": "F-120",
    "bbl:P10022": "F-20",   
    "cdf:type": [
      "bbl:P10924",
      "bbl:P101907",
      "bbl:P101003632",
      "bbl:P13932",
      "bbl:P21",
      "iso15926:InanimatePject",
      "iso15926:Object",
      "Moomos:PopoFeedTag"
    ],
    "primarycdf:type": "bbl:P924"
  }
]

>Solution :

Your example is a single object inside an array.

@SeeSharp propose to wrap that array.

The opposite way is, if that’s always the case, that you can just parse the object inside that array (removing first and last character):

var json = JObject.Parse(jStr.Remove(str.Length - 1).Remove(0, 1));

Otherwise, I guess you just adapt your code to handle an array, and not an object (which looks the better way to do so)

EDIT :

Since there is multiple object inside your JArray, just iterate over it :

foreach (JObject item in JArray.Parse(jStr)) 
{
  DoStuffOnJObject(item) // call your method
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading