- Home /
Question by
James Simpson · Apr 19, 2010 at 03:32 AM ·
objectstringsmartfox
Parse string object from SmartFoxServer
I am trying to make an extension for SmartFoxServer and want to send the data in the raw format rather than xml. I know this is probably a really stupid question, but I can't seem to figure out how to parse the data when I get it back.
public void OnExtensionResponse(object data, string type) {
Debug.Log(data);
}
This outputs the full data string with the % delimiter. However, when I try the following I get an error:
public void OnExtensionResponse(object data, string type) {
Debug.Log(data[0]);
}
error CS0021: Cannot apply indexing with [] to an expression of type `object'
Comment
Best Answer
Answer by duck · Apr 19, 2010 at 09:10 AM
Are you trying to get the first character of the string? If "data" contains a string, you just need to cast it to a string before trying to use it as such (because of the parameter type, it starts as a generic 'object' type).
public void OnExtensionResponse(object data, string type) {
// cast to string type:
string dataString = (string)data;
// now we can access the chars in the string:
Debug.Log( dataString[0] );
}