NSString to Byte Array

Discussion in 'Mac Programming' started by donaghy, Sep 18, 2009.

  1. donaghy macrumors member

    Joined:
    Aug 6, 2009
    #1
    Is it possible to convert a NSString to a byte array? I'm not sure how to do this, help appreciated.

    cheers.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
  3. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    I'm not sure why you would want to do this, and usually with questions like this you are barking up the completely wrong tree.

    Please tell us exactly what it is that you actually want to achieve (and "I want to access the contents of the string as bytes" is _not_ what you want to achieve).
     
  4. donaghy thread starter macrumors member

    Joined:
    Aug 6, 2009
    #4
    I've got a response from a webservice that i've parsed, its contains a timestamp field. I use this timestamp field when i want to update a record. To update a record I sent another request to a webservice passing the timestamp as a parameter, however I get the error cannot convert string to byte[]. The timestamp value that i store from the initial response looks something like 'AAAAAAAA1A4=' and is stored as an NSString.
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    Is this Java or Objective-C? I'm wondering because there is no byte[] type in Objective-C, AFAIK. Maybe you're paraphrasing the error message wrong, which fails on another count: never paraphrase error messages, always copy and paste them exactly.

    What type does your webservice request need? Be specific. If it's unclear, simply post the failing code, along with the type declarations of any variables it's using.
     
  6. donaghy thread starter macrumors member

    Joined:
    Aug 6, 2009
    #6
    The webservice is coded in VB.Net, its currently being used by a .net based mobile application. We are lookin to move from the .net mobile platform to an iphone app but want to maintain our .net webservice.

    The webservice itself requests a username (string), password(string), Id(int), description (string) and timestamp (object). The error message is 'could not convert string to byte[]', i get the same error message when i test this directly through a .net environment against the web service.
     
  7. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #7
    So the error message doesn't come from your own software, but from the web service? In that case, what kind of data does the service expect? HTMP Post messages? XML? You'd need to get the documentation what the web service expects, and send exactly what it wants.
     
  8. donaghy thread starter macrumors member

    Joined:
    Aug 6, 2009
    #9
    The webservice is expecting a parameter that is a Byte[], which according to msdn documentation is an 8-bit unsigned integer. The value i'm reading from the webservice is 'AAAAAAAAs00='. The exact error generated by the webservice is "Failed to convert parameter value from a string to a Byte[]". Would it be a matter of converting the value 'AAAAAAAAs00=' to an unsigned 8-bit integer? Im not aware of how the value is being encoded to achieve 'AAAAAAAAs00=', would this be something the xml response is doing as its says encoding="utf-8"?
     
  9. donaghy thread starter macrumors member

    Joined:
    Aug 6, 2009
    #10
    Ok i think i've got a little further. It appears to be base64binary conversion and i think i can handle in conversion in the webservice, although if anyone knows how to convert from base64binary let me know.
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #11
    Google search term: base64

    Wikipedia search term: base64

    You can find any number of freely available base64 conversions simply by looking. To find ones for a particular computer language, add the language name to the search terms.
     

Share This Page