Calculating a sum of received bitcoins
Transactions can have multiple outputs, and multiple inputs. The valueIn field is the sum of all of the inputs of the transaction, not the amount going toward the address you're interested in.

Instead of summing valueIn, you should make a list of all of the outputs, then filter out the ones that aren't sent to the address you're interested in, then sum those up.


  Fun fact: blockexplorer.com returns a value of totalReceived that is different from a value returned by blockchain.info.


The meaning of 'total received' is not well-defined. For example, if I take money at address A, and send it to address A, has address A "received" money? Different APIs calculate this differently.

Note: I assume you're intentionally not looking to find the balance of the address, which is well-defined.