How to sell a piece of data through blockchain? User A attempts to sell a piece of data D (byte level) to user B at price C through the blockchain. A and B do not trust each other. A worry: After the data D is delivered, B does not complete the transfer; B worry: After completing the transfer, A does not send data D, or sends invalid data D. How to design a reasonable mechanism to protect the interests of both parties?
Etherium handles this. You need a trusted Escrow, If you don't trust a single third party you can use smart contracts to use the network as a distributed trusted third party.
You don't trust any single member of the network or even small conspiring groups you trust the network as whole.

With a smart contract you will provide a commitment on the data you wish to send(possibly a key allowing decrypting other data). You will supply a zero knowledge proof you hold a value matching the commitment as well as other proprerties(matches what you want to send).
Notice this assumes the buyer can verify the data he is buying.

The smart contract goes on the blockchain, and enforces the contract when one side provides publicly a value matching the commitment it can be verified by the contract and funds will be "transferred" on the ledger.

The contract is a program executed by multiple parties on the network, you pay them for their services. In etherium this is the cost of fuel.