Advertisement
Guest User

Untitled

a guest
Nov 27th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <b>Update</b>
  2.  
  3. @kyrohiro suggested to use the `hasOwnKey()` method. However, this seems to only work with top level nodes in a JSON, and not the child nodes. For example, if you have JSON structure like this (in a readable form, sans the JSON syntax), you can check for the existence of `callresponder.lastResponse.hasOwnKey("Location")`, but there seems no way to check for `Location.VenueName` for example or any of the children:
  4.  
  5. <pre>
  6. Name:
  7. Location:
  8. (child) VenueName:
  9. (child) Address:
  10. (child) City:
  11. (child) State:
  12. .
  13. .
  14. . (etc)
  15. </pre>
  16.  
  17. The issue is that my data source omits the child key when the information is not available, so it would be nice to be able to check for the existence of the JSON key in a reference in Flex before doing anything else for it.
  18.  
  19. <b>Q: How would I check if the JSON key `Location.VenueName` exists? </b>
  20.  
  21. -----
  22.  
  23. When the key does not exist and Flex tries pulling it from callresponder.lastResult, here is the error dump:
  24.  
  25. com.adobe.serializers.json::JSONDecoder/parseObject
  26. com.adobe.serializers.json::JSONDecoder/parseValue
  27. com.adobe.serializers.json::JSONDecoder/decode
  28. com.adobe.serializers.json::JSONSerializationFilter/deserializeResult
  29. mx.rpc.http::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::processResult
  30.  
  31. -----
  32.  
  33. And posting the error dump for `if(callresponder.lastResult.Location.VenueName)` for case where the key is not in the JSON, for @www-flexextras-com
  34.  
  35. mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler
  36. mx.rpc::Responder/result
  37.  
  38.  
  39. TypeError: Error #1009: Cannot access a property or method of a null object reference.
  40. at views::UserInfoView/parsePlayerInfo()[/Users/ina/src/views/UserInfoView.mxml:69]
  41. at flash.events::EventDispatcher/dispatchEventFunction()
  42. at flash.events::EventDispatcher/dispatchEvent()
  43. at mx.rpc::CallResponder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\CallResponder.as:122]
  44. at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:239]
  45. at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:207]
  46. at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:244]
  47. at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
  48. at mx.rpc::Responder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
  49. at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
  50. at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
  51. at flash.events::EventDispatcher/dispatchEventFunction()
  52. at flash.events::EventDispatcher/dispatchEvent()
  53. at flash.net::URLLoader/onComplete()
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement