- Home /
 
               Question by 
               SLaYeRReBoRN · May 18, 2017 at 11:01 AM · 
                unity 5javascriptscripting problem  
              
 
              How to handle A keyNoteFound Exception without Using A try catch Block?
JavaScript
if (prop ["normalcolor"] != null ) { Do Something }  I wanna Skip this block of code When it is'nt available in the json. Using the Javascript written i get an error saying KeynotFoundException. I wanna handle this without a try and catch block . Any ideas?. In addition i was able to use this logic in c# and it works. 
               Json
{ "item":"af-button", "props":{ "label":"Hello1", "highlightedcolor":"#a1d15e", "inverted": "true" } 
               1 more approach that works with c# But in Javascript It throws the same exception
 static function JsonDataContainsKey ( data : JsonData, key : String ) { var result = false; if (data == null) return result; if (!data.IsObject) { return result; } var tdictionary = data as IDictionary; if (tdictionary == null) return result; if (tdictionary.Contains (key)) { result = true; } return result; } 
              
               Comment
              
 
               
              Answer by SLaYeRReBoRN · May 25, 2017 at 07:07 AM
Solved By using prop.key.contains("props") where props is the json Using LitJson libraries.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                