This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val titleString = root.pointer.at("/0/title").safeString | |
assertEquals("delectus aut autem",titleString) | |
val completed = root.pointer.at("/3/completed").safeBoolean | |
assertTrue(completed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
if(root is JsonArray && root.size() > 0){ //Smart cast 1 | |
val firstElem = root[0] | |
if(firstElem is JsonObject){ | |
val title = firstElem.get("title") //Smart cast 2 | |
if (title != null && title is JsonPrimitive && title.isString){ //Smart cast 3 | |
val titleString = title.asString | |
assertEquals("delectus aut autem",titleString) | |
} | |
val completed = firstElem.get("id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun getTodos(){ | |
OkHttpClient().newCall(Request.Builder().url("https://jsonplaceholder.typicode.com/todos").build()).enqueue(object : Callback { | |
override fun onFailure(call: Call?, e: IOException?) {} //Handle Network failure | |
override fun onResponse(call: Call?, response: Response?) { | |
response!!.body()!!.use {responsebody -> | |
val root = JsonParser().parse(responsebody.charStream()) | |
assertTrue(root is JsonElement) //root is a JsonElement object | |
assertTrue(root is JsonArray) //root is actually, a JsonArray object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am dhiraj on github. | |
* I am dhiraj (https://keybase.io/dhiraj) on keybase. | |
* I have a public key ASCtWqmgDKyi-1-GaEDW6W_MdXHA0xb-azCAZ3JybzxVAAo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// KeyPath.swift | |
// GIFMosCore | |
// | |
// Copied liberally by Dhiraj Gupta on 4/27/17 from https://oleb.net/blog/2017/01/dictionary-key-paths/ | |
// | |
import Foundation | |
public struct KeyPath { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am dhiraj on github. | |
* I am dhiraj (https://keybase.io/dhiraj) on keybase. | |
* I have a public key whose fingerprint is B1A2 1616 C66E CD49 F6E8 0582 3A81 C9D5 1C4B 8B39 | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
"Album Rating Reset" for iTunes | |
written by Doug Adams | |
dougadams@mac.com | |
v1.0 sept 6 2007 | |
-- initial release | |
v2.0 mar 6 2013 | |
updated by Dhiraj Gupta (http://www.dhirajgupta.com) |