Re: [web-nfc] NFCReadingEvent has an attribute with a type of dictionary? (#232)

> By my understanding, Body provides json(), arrayBuffer(), text(), blob() etc. for getting multiple forms of data from only one given data source, all of them could return meaningful things, while our NDEFRecord seems a different case that the data type for a given NDEFRecord instance is fixed, it can only be one type, either String, or ArrayBuffer, or JSON, i.e. calling json() on a record with array buffer data will just get null.

That is pretty much the same case here. JSON is also stored as text and can be read as text() or arrayBuffer() with no problem.

Look at the definitions

JSON
* Return the result of running parse JSON from bytes on bytes.

text
* Return the result of running UTF-8 decode on bytes.

arrayBuffer
* Return a new ArrayBuffer whose contents are bytes.

Blob
* Return a Blob whose contents are bytes and type attribute is mimeType.

You do have some point though, as we attempt to store things in an organized fashion. https://w3c.github.io/web-nfc/#data-mapping

* text and url are stored in TNF 1, so everything else than `text()` should probably just return null.
* data with mime type is stored in TNF 2, and it should be fine to make `text()`, `json()`, `arrayBuffer()` and `blob()` work.
* data with no mime type is stored in TNF 4, so everything but `blob()` should work as blob requires mime type.






-- 
GitHub Notification of comment by kenchris
Please view or discuss this issue at https://github.com/w3c/web-nfc/issues/232#issuecomment-511734894 using your GitHub account

Received on Tuesday, 16 July 2019 09:13:18 UTC