-5

Below is my JSON

{
  "mname":
   [
     {
       "Mname":"abc",
       "pname":[],
       "rewards":null
     }
   ]
}

How to check the reward array contains a null value?

Kunj
  • 1,980
  • 2
  • 22
  • 34
  • 1
    Welcome to Stack Overflow. Please read [Stack Overflow: How to ask](http://stackoverflow.com/questions/how-to-ask) and [Jon Skeet's Question Checklist](http://msmvps.com/blogs/jon_skeet/archive/2012/11/24/stack-overflow-question-checklist.aspx) to find out how to ask a good question that will generate good useful, answers. – Our Man in Bananas Jul 08 '14 at 09:18
  • Your json is a bit wrong, missing some curly brackets. Try to evaluate it first. – Adrian Toma Jul 08 '14 at 09:19
  • Use http://jsonlint.com/ to validate the JSON. – Kunj Jul 08 '14 at 09:27

2 Answers2

1

Try this code ,

    var data = {
         "mname": [
             {
                "Mname": "abc",
                "pname": [],
                "rewards": null
             }
          ]
     }

     $.each( data.mname , function( key, value ) {
         if(value.rewards == null || value.rewards == undefined){
                 // Add your codes/logic
         }
     });
Manu Benjamin
  • 987
  • 9
  • 24
  • 1
    Good answer! Can use `===` as well to speedup the execution. Read more here - http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons – Kunj Jul 08 '14 at 11:52
0

try this

var data = {
  "mname":
   [
     {
       "Mname":"abc",
       "pname":[],
       "rewards":null
     }
   ]
}

if(data.mname[0].rewards == null || data.mname[0].rewards == undefined){


}
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49