dya2 / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

JSONArray nested in JSONObject is not supported (patch provided) #614

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This breaks extra in Intents like android.intent.action.SEND in py4a example 
below:

import android
    droid = android.Android()
    myintent=droid.makeIntent("android.intent.action.SEND",\
    None, \
    "image/jpeg", \
    {"android.intent.extra.STREAM" : fileURI, \
    "android.intent.extra.TEXT":"My email body", \
    "android.intent.extra.SUBJECT":"My Email title", \
    "android.intent.extra.EMAIL":("me@gmail.com",)}, \
    ("android.intent.category.DEFAULT",)).result
    print myintent   
    droid.startActivityIntent(myintent)

The issue is that SL4a skips the JSONArray nested in JSONObject - notice that 
there is no email in the output of print:

{u'action': u'android.intent.action.SEND',
 u'type': u'image/jpeg', u'extras':
 {u'android.intent.extra.SUBJECT': u'My Email title',
  u'android.intent.extra.TEXT': u'My email body',
  u'android.intent.extra.STREAM': u'file:///sdcard/DCIM/100MEDIA/IMAG0289.jpg'},
 u'flags': 268435456,
 u'categories': [u'android.intent.category.DEFAULT']}

The provided patch adds limited support for JSONArray nested in JSONObject and 
recursive JSONObject.
Patch does not support three array structures that come to my mind: empty 
arrays, arrays with null (py4a (None,None)) members and mixed member types in a 
single array (including mix of any type with none).
The patch has been tested with example above and works well. Recursive 
JSONObjects have not been tested (Don't have a test scenario).
I've never touched Java before (and don't claim any knowledge of it), so the 
code likely needs a lot of cleanup.

Original issue reported on code.google.com by zele...@gmail.com on 19 Mar 2012 at 4:31

Attachments:

GoogleCodeExporter commented 9 years ago
Included in r5x

Original comment by rjmatthews62 on 21 Mar 2012 at 4:58