public NDEFMessage()
 {
     records    = new List <NDEFRecord>();
     tagID      = string.Empty;
     writeState = NDEFMessageWriteState.IDLE;
     writeError = NDEFMessageWriteError.NONE;
 }
        public void ParseJSON(JSONObject jsonObject)
        {
            JSONArray recordsJSON;

            if (jsonObject.TryGetArray("records", out recordsJSON))
            {
                int length = recordsJSON.Length;
                records = new List <NDEFRecord>();
                for (int i = 0; i < length; i++)
                {
                    JSONObject recordJSON = recordsJSON[i].Object;
                    int        typeValue;
                    recordJSON.TryGetInt("type", out typeValue);
                    NDEFRecordType type   = (NDEFRecordType)typeValue;
                    NDEFRecord     record = null;
                    switch (type)
                    {
                    case NDEFRecordType.ABSOLUTE_URI: record = new AbsoluteUriRecord(recordJSON); break;

                    case NDEFRecordType.EMPTY: record = new EmptyRecord(recordJSON); break;

                    case NDEFRecordType.EXTERNAL_TYPE: record = new ExternalTypeRecord(recordJSON); break;

                    case NDEFRecordType.MIME_MEDIA: record = new MimeMediaRecord(recordJSON); break;

                    case NDEFRecordType.SMART_POSTER: record = new SmartPosterRecord(recordJSON); break;

                    case NDEFRecordType.TEXT: record = new TextRecord(recordJSON); break;

                    case NDEFRecordType.UNKNOWN: record = new UnknownRecord(recordJSON); break;

                    case NDEFRecordType.URI: record = new UriRecord(recordJSON); break;
                    }

                    records.Add(record);
                }
            }
            else
            {
                records = new List <NDEFRecord>();
            }

            jsonObject.TryGetString("tag_id", out tagID);

            int writeStateValue;

            jsonObject.TryGetInt("write_state", out writeStateValue);
            writeState = (NDEFMessageWriteState)writeStateValue;

            int writeErrorValue;

            jsonObject.TryGetInt("write_error", out writeErrorValue);
            writeError = (NDEFMessageWriteError)writeErrorValue;
        }