What am I doing wrong here? Where is failing

Aug 3, 2012 at 2:31 PM

Please see comments in code... One just doesn't work, the other throws exceptions. Can I do this?

 

Thanks

Ralph

 

CODE...
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/Support/linq.js" type="text/javascript"></script>
    <script type="text/javascript">

        var objData = JSON.parse('[{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/17/2012","Count":7},{"Date":"7/18/2012","Count":2},{"Date":"7/19/2012","Count":2},{"Date":"7/20/2012","Count":4},{"Date":"7/23/2012","Count":1},{"Date":"7/26/2012","Count":1},{"Date":"7/30/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":9},{"Date":"7/18/2012","Count":3}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":3}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/13/2012","Count":1},{"Date":"7/17/2012","Count":3},{"Date":"7/25/2012","Count":5},{"Date":"7/26/2012","Count":4},{"Date":"7/30/2012","Count":2}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":2},{"Date":"7/23/2012","Count":1},{"Date":"7/25/2012","Count":2},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/13/2012","Count":1},{"Date":"7/17/2012","Count":3}],"ModuleName":"Module 6"}],"UserName":"afox"},{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/23/2012","Count":2},{"Date":"7/25/2012","Count":1},{"Date":"7/31/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":1}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":2},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":1},{"Date":"7/25/2012","Count":1},{"Date":"7/30/2012","Count":1}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/23/2012","Count":1},{"Date":"7/24/2012","Count":2},{"Date":"7/25/2012","Count":2}],"ModuleName":"Module 6"}],"UserName":"bsmith"},{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":3},{"Date":"7/17/2012","Count":7},{"Date":"7/18/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/20/2012","Count":1},{"Date":"7/23/2012","Count":2},{"Date":"7/25/2012","Count":2},{"Date":"7/27/2012","Count":8},{"Date":"7/30/2012","Count":1},{"Date":"8/3/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/27/2012","Count":3}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/16/2012","Count":2},{"Date":"7/27/2012","Count":2}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/18/2012","Count":3},{"Date":"7/19/2012","Count":2},{"Date":"7/23/2012","Count":1},{"Date":"7/24/2012","Count":8},{"Date":"7/25/2012","Count":2},{"Date":"7/26/2012","Count":1},{"Date":"7/27/2012","Count":1},{"Date":"8/3/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"ateam"},{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/17/2012","Count":1},{"Date":"7/20/2012","Count":1},{"Date":"7/23/2012","Count":2},{"Date":"7/25/2012","Count":2},{"Date":"8/1/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":3},{"Date":"7/24/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"NGenEditor"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/20/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"dbebeh"},{"Views":[{"ConnectedTimes":[{"Date":"7/24/2012","Count":1}],"ModuleName":"Module 2"}],"UserName":"eberg"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":3},{"Date":"7/13/2012","Count":1},{"Date":"7/15/2012","Count":1},{"Date":"7/16/2012","Count":1},{"Date":"7/17/2012","Count":1},{"Date":"7/18/2012","Count":1},{"Date":"7/19/2012","Count":3},{"Date":"7/23/2012","Count":7},{"Date":"7/25/2012","Count":3},{"Date":"7/26/2012","Count":3},{"Date":"7/30/2012","Count":1},{"Date":"7/31/2012","Count":2},{"Date":"8/2/2012","Count":2}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":2},{"Date":"7/18/2012","Count":1},{"Date":"7/23/2012","Count":5},{"Date":"7/26/2012","Count":4},{"Date":"7/30/2012","Count":1},{"Date":"8/2/2012","Count":4}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":2},{"Date":"7/26/2012","Count":6},{"Date":"7/30/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/13/2012","Count":1},{"Date":"7/15/2012","Count":1},{"Date":"7/18/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/23/2012","Count":4},{"Date":"7/26/2012","Count":1},{"Date":"8/2/2012","Count":2}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":5},{"Date":"7/25/2012","Count":1},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":4},{"Date":"7/24/2012","Count":4},{"Date":"7/25/2012","Count":1},{"Date":"8/2/2012","Count":4}],"ModuleName":"Module 6"}],"UserName":"gwall"},{"Views":[{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/21/2012","Count":1},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1}],"ModuleName":"Module 2"}],"UserName":"mrivera"},{"Views":[{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/24/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"rjenson"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":2},{"Date":"7/13/2012","Count":1},{"Date":"7/16/2012","Count":1},{"Date":"7/17/2012","Count":2},{"Date":"7/18/2012","Count":3},{"Date":"7/20/2012","Count":4},{"Date":"7/25/2012","Count":4},{"Date":"7/27/2012","Count":1},{"Date":"8/2/2012","Count":9}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/20/2012","Count":1}],"ModuleName":"NGenEditor"},{"ConnectedTimes":[{"Date":"8/2/2012","Count":21},{"Date":"8/3/2012","Count":2}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"8/2/2012","Count":7},{"Date":"8/3/2012","Count":2}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"8/2/2012","Count":2},{"Date":"8/3/2012","Count":3}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/20/2012","Count":2},{"Date":"7/24/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":2}],"ModuleName":"Module 6"}],"UserName":"rkrausse"},{"Views":[{"ConnectedTimes":[{"Date":"7/23/2012","Count":1}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":1},{"Date":"7/24/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"yfarrell"}],"Site":"Site 1","Valid":true},{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/17/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"ateam"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"dbebeh"}],"Site":"Site 2","Valid":true},{"Users":[],"Site":"Site 3","Valid":true},{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":3},{"Date":"7/18/2012","Count":2},{"Date":"7/19/2012","Count":2},{"Date":"7/23/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":2}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":4}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":3}],"ModuleName":"Module 6"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":5},{"Date":"7/17/2012","Count":4},{"Date":"7/18/2012","Count":2}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":2}],"ModuleName":"Module 9"}],"UserName":"afox"},{"Views":[{"ConnectedTimes":[{"Date":"7/13/2012","Count":2},{"Date":"7/16/2012","Count":3},{"Date":"7/18/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/23/2012","Count":1},{"Date":"8/3/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/23/2012","Count":1},{"Date":"8/3/2012","Count":1}],"ModuleName":"NGenEditor"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/18/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"ateam"},{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/23/2012","Count":1},{"Date":"7/24/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"dbebeh"},{"Views":[{"ConnectedTimes":[{"Date":"7/16/2012","Count":2},{"Date":"7/31/2012","Count":1},{"Date":"8/1/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/16/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/31/2012","Count":1}],"ModuleName":"Module 3"}],"UserName":"gwall"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/18/2012","Count":1}],"ModuleName":"Module 4"}],"UserName":"jberry"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":2},{"Date":"7/18/2012","Count":1},{"Date":"7/19/2012","Count":4},{"Date":"7/20/2012","Count":15},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/20/2012","Count":17},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/19/2012","Count":1},{"Date":"7/20/2012","Count":15},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 4"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/20/2012","Count":6},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/20/2012","Count":7},{"Date":"7/26/2012","Count":1}],"ModuleName":"Module 6"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/20/2012","Count":8}],"ModuleName":"Module 2"}],"UserName":"mrivera"},{"Views":[{"ConnectedTimes":[{"Date":"7/12/2012","Count":3},{"Date":"7/16/2012","Count":1},{"Date":"7/18/2012","Count":4},{"Date":"7/23/2012","Count":2},{"Date":"7/25/2012","Count":6}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1}],"ModuleName":"Module 3"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":1},{"Date":"7/16/2012","Count":1},{"Date":"7/18/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/12/2012","Count":2}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/11/2012","Count":1}],"ModuleName":"Module 9"}],"UserName":"rkrausse"}],"Site":"Site 4","Valid":true},{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/18/2012","Count":2},{"Date":"7/19/2012","Count":1},{"Date":"7/20/2012","Count":1},{"Date":"7/23/2012","Count":2},{"Date":"7/24/2012","Count":1},{"Date":"7/25/2012","Count":2},{"Date":"7/31/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/25/2012","Count":1}],"ModuleName":"NGenEditor"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":2},{"Date":"7/20/2012","Count":1}],"ModuleName":"Module 5"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1}],"ModuleName":"Module 6"}],"UserName":"ateam"},{"Views":[{"ConnectedTimes":[{"Date":"7/18/2012","Count":2},{"Date":"7/23/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"dbebeh"},{"Views":[{"ConnectedTimes":[{"Date":"7/19/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"rkrausse"}],"Site":"Site 5","Valid":true},{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/25/2012","Count":4}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/19/2012","Count":1},{"Date":"7/25/2012","Count":2}],"ModuleName":"Module 6"},{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 2"},{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 4"}],"UserName":"afox"},{"Views":[{"ConnectedTimes":[{"Date":"7/25/2012","Count":1}],"ModuleName":"Module 1"}],"UserName":"rkrausse"}],"Site":"Site 6","Valid":true},{"Users":[{"Views":[{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/18/2012","Count":3}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/18/2012","Count":2}],"ModuleName":"NGenEditor"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1},{"Date":"7/18/2012","Count":3},{"Date":"7/19/2012","Count":1}],"ModuleName":"Module 6"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":3},{"Date":"7/18/2012","Count":2}],"ModuleName":"DE"}],"UserName":"ateam"},{"Views":[{"ConnectedTimes":[{"Date":"7/17/2012","Count":1}],"ModuleName":"Module 1"},{"ConnectedTimes":[{"Date":"7/17/2012","Count":1}],"ModuleName":"DE"}],"UserName":"dbebeh"}],"Site":"Site 7","Valid":true},{"Users":[],"Site":"Site 8","Valid":false},{"Users":[],"Site":"Site 9","Valid":false},{"Users":[],"Site":"Site 10","Valid":false},{"Users":[],"Site":"Site 11","Valid":false}]');
        // works
        var aSite = Enumerable.From(objData).Where('$.Site == "Site 1"').ToArray();
        // how do I make this work - note this just doesn't return data
        var aUsers = Enumerable.From(objData.Users).Where('$.UserName == "afox"').ToArray();
        // or this one - this one throws an exception
        var aConnectedTimes = Enumerable.From(objData.Users.Views.ConnectedTimes).Where('$.Count == 7').ToArray();
    </script>
  </head>
<body>


</body>
</html>

Coordinator
Aug 5, 2012 at 5:20 PM

At first, objData is array.

That is objData.Users is undefined.

Therefore objData.Users.Views throws exception.

following code may get your expected result.

var aUsers = Enumerable.From(objData).SelectMany("$.Users").Where('$.UserName == "afox"').ToArray();