elCapitano
elCapitano

Reputation: 1841

can i use a keyword as a propertyname in vb .net?

I have to serialize/deserialize a class into a JSON string/and return. The JSON Strinig must contain the "error" string (like: {error:"something strange occoured", id:23, result:"xxxxx"}), which specifies the occoured error.

How can i implement a class like:

Public Class JsonResponse
    Public result As JsonResult
    Public error As String
    Public id As Integer
 End Class

If i do this, the word 'error' is invalid.

Thanks

Upvotes: 4

Views: 2235

Answers (2)

GrandMasterFlush
GrandMasterFlush

Reputation: 6409

Use [] around the name:

Public Class JsonResponse
   Public result As JsonResult
   Public [error] As String
   Public id As Integer
End Class

Upvotes: 1

Dean
Dean

Reputation: 5946

Surround it with square brackets

Public Class JsonResponse
    Public result As JsonResult
    Public [error] As String
    Public id As Integer
 End Class

HTH

Upvotes: 10

Related Questions