Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
I

inquisitive_1

@inquisitive_1
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray
    I inquisitive_1

    I'm getting the following error: NullReferenceException: Object reference not set to an instance of an object.

    C# question csharp database xml json

  • JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray
    I inquisitive_1

    Sorry. I don't have any control over that. Yes, it makes more sense if it was always an array, but that's what I get from the web service feed.

    C# question csharp database xml json

  • JSON.Net - Error when I get value from a JToken that could be either a JValue or JArray
    I inquisitive_1

    I'm trying to select all users with a roleId of 4. How can I do that? Here's my JSON string:

    {
    "?xml" : {
    "@version" : "1.0",
    "@encoding" : "UTF-8"
    },
    "DataFeed" : {
    "@FeedName" : "AdminData",
    "People" : [{
    "id" : "63",
    "active" : "1",
    "firstName" : "Joe",
    "lastName" : "Schmoe",
    "roleIds" : {
    "int" : "4"
    }
    } , {
    "id" : "65",
    "active" : "1",
    "firstName" : "Steve",
    "lastName" : "Jobs",
    "roleIds" : {
    "int" : ["4", "16", "25", "20", "21", "22", "17", "23", "18"]
    }
    } , {
    "id" : "66",
    "active" : "1",
    "firstName" : "Bill",
    "lastName" : "Gates",
    "roleIds" : {
    "int" : ["3", "16", "25", "20"]
    }
    }
    ]
    }
    }

    Here's the query that I'm using:

    JObject jsonFeed = JObject.Parse(jsonText);

    from people in jsonFeed.SelectTokens("DataFeed.People").SelectMany(i => i.ObjectsOrSelf())
    where (int)people\["active"\] == 1 && (int)people\["roleIds.int"\] == 4 // <-- this causes the error
    select new PeopleClass
    {
    	Id = (int)people\["id"\],
    	ResAnFName = (string)people\["firstName"\],
    	ResAnLName = (string)people\["lastName"\]
    }
    

    I'm getting the following error on (int)people["roleIds.int"] == 4: ArgumentNullException: Value cannot be null. Parameter name: value In the end, my results should be: Joe Schmoe & Steve Jobs, only. What am I doing wrong?

    C# question csharp database xml json
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups