Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to write a <code>showJSON</code> and <code>readJSON</code> method, for your type, that builds your Haskell values out of the JSON format. The JSON package will take care of parsing the raw string into a <a href="http://hackage.haskell.org/packages/archive/json/0.4.4/doc/html/src/Text-JSON-Types.html#JSValue" rel="noreferrer"><code>JSValue</code></a> for you.</p> <p>Your tweet will be a <code>JSObject</code> containing a map of strings, most likely. </p> <ul> <li>Use <code>show</code> to look at the JSObject, to see how the fields are laid out.</li> <li>You can lookup each field using <code>get_field</code> on the <code>JSObject</code>. </li> <li>You can use <code>fromJSString</code> to get a regular Haskell strings from a <code>JSString</code>.</li> </ul> <p>Broadly, you'll need something like,</p> <pre><code>{-# LANGUAGE RecordWildCards #-} import Text.JSON import Text.JSON.Types instance JSON Tweet where readJSON (JSObject o) = return $ Tweet { .. } where from_user = grab o "from_user" to_user_id = grab o "to_user_id" profile_image_url = grab o "proile_image_url" created_at = grab o "created_at" id_str = grab o "id_str" source = grab o "source" to_user_id_str = grab o "to_user_id_str" from_user_id_str = grab o "from_user_id_str" from_user_id = grab o "from_user_id" text = grab o "text" metadata = grab o "metadata" grab o s = case get_field o s of Nothing -&gt; error "Invalid field " ++ show s Just (JSString s') -&gt; fromJSString s' </code></pre> <p>Note, I'm using the rather cool wild cards language extension.</p> <p>Without an example of the JSON encoding, there's not much more I can advise.</p> <hr> <p><em>Related</em></p> <p>You can find example instances for the JSON encoding via instances</p> <ul> <li><a href="http://hackage.haskell.org/packages/archive/json/0.4.4/doc/html/src/Text-JSON.html#JSON" rel="noreferrer">in the source</a>, for simple types. Or in other packages that depend on json. </li> <li>An instance for AUR messages <a href="http://hackage.haskell.org/packages/archive/archlinux/0.3.3/doc/html/src/Distribution-ArchLinux-AUR.html#AURInfo" rel="noreferrer">is here</a>, as a (low level) example.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload