iOS Question How to get map to group key/value pairs

Discussion in 'iOS Questions' started by davepamn, Feb 26, 2015.

  1. davepamn

    davepamn Active Member Licensed User

    I need my json string to format

    [{"key":"1","keyvalue":"a"},{"key":"2","keyvalue":"b"}]

    Code:
    Server Code:

    <Serializable> _
        
    Public Class cKeyItem
            
    Private m_key As String
            
    Private m_keyValue As String
            PublicProperty key() AsString
                Get
                    
    Return m_key
                
    End Get
                Set(value 
    As String)
                    m_key = value
                
    End Set
            EndProperty
            
    Public Property keyValue() As String
                Get
                    
    Return m_keyValue
                
    End Get
                Set(value 
    As String)
                    m_keyValue = value
                
    End Set
            EndProperty
        EndClass

    <WebMethod()> _
    Sub Save(sJSON as string)
    Dim jSearializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()

            
    Dim objItemList = jSearializer.Deserialize(Of List(Of cKeyItem))(sJSON)
            
    Dim oKeyItem As cKeyItem
            
    For Each oKeyItem In objItemList
                sRetVal = sRetVal & oKeyItem.key & 
    "=" & oKeyItem.keyValue
            
    Next
    End Sub
    How do I get the map function to serialize the json string into key value pairs?

    Code:
    Dim sJSONString As String
        
    Dim oJSONGenerator As JSONGenerator
        oJSONGenerator.Initialize2(oKeyValueList)
        sJSONString=oJSONGenerator.ToString
     
    Last edited: Mar 2, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    [{"key":"1","keyvalue":"a"},{"key":"2","keyvalue":"b"}]
    Code:
    Dim values As List = Array(CreateMap("key""1""keyvalue""a"), CreateMap("key""2""keyvalue""b"))
    Dim jg As JsonGenerator
    jg.Initialize2(values)
    log(jg.ToString)
     
  3. davepamn

    davepamn Active Member Licensed User

    thanks
     
  4. davepamn

    davepamn Active Member Licensed User

    jobTestIdValues.Download2("http://server/Save", Array As String("sJSON",sJSONString))

    I tested a large JSON string on the server and it worked.

    There seems to be a problem with the sJSONString on the client.

    Code:
    Dim oKeyValueList As List
    oKeyValueList.Initialize

    ... (
    loop)
    oKeyValueList.Add(CreateMap(
    "key":sTestId,"keyvalue":sTestValue))  '100 of these tests
    ...

    Dim sJSONString As String
    Dim oJSONGenerator As JSONGenerator
    oJSONGenerator.Initialize2(oKeyValueList)
    sJSONString=oJSONGenerator.ToString

    Msgbox(sJSONString,"json")

    Dim jobTestIdValues As HttpJob

    jobTestIdValues.Initialize(
    "JobSaveTestIdValues",Me)
    jobTestIdValues.Download2(
    "http://www.abc.com/Save", ArrayAsString("sJSON",sJSONString))
    The msgbox shows the JSON string is being generated correctly.

    The code works for 20 tests.
     
    Last edited: Mar 2, 2015
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please post the code and the error from the logs.
     
  6. davepamn

    davepamn Active Member Licensed User

    Last edited: Mar 2, 2015
  7. davepamn

    davepamn Active Member Licensed User

    I wrote a VB app and set a large JSON string to the server and it parsed. The asp.net server works.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You should create a POST request and send the string as the post payload. This way there won't be any limit.
     
  9. davepamn

    davepamn Active Member Licensed User

    Code:
    Dim jobTestIdValues As HttpJob
    jobTestIdValues.Initialize(
    "JobSaveTestIdValues",Me)
    jobTestIdValues.PostString(
    "http://www.abc.com/Save""sJSON=" & sJSONString)
    This Worked!
     
  10. davepamn

    davepamn Active Member Licensed User

    Thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice