summaryrefslogtreecommitdiff
path: root/docs/class-simplejson.JSONDecoder.html
blob: c5f31ffec72f399bb4cadbe14d1fd0bfb8bce1fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  
  <HEAD><META CONTENT="text/html; charset=utf-8" HTTP-EQUIV="Content-Type">
    <TITLE>simplejson.JSONDecoder -- Simple JSON &amp;lt;&lt;a class="reference" href="http://json.org">http://json.org&lt;/a>&amp;gt; decoder</TITLE>
    <LINK HREF="layout.css" TYPE="text/css" REL="stylesheet">
  </HEAD>
  <BODY>
    <DIV ID="page">
      
    <DIV ID="top-nav">
        <H1 ID="doc-title"><A HREF="index.html" REL="index">simplejson 1.7.1</A></H1>
        <DIV CLASS="online-navigation">
          <A HREF="index.html" REL="index">index</A>
          <SPAN ID="nav-docs">
            
          </SPAN>
          
          

          <BR>

          <A HREF="module-simplejson.html" TITLE="simplejson reference">
            simplejson
          </A>

          
            
            <A HREF="class-simplejson.JSONDecoder.html">details</A>
            
            <A HREF="class-simplejson.JSONDecoder-index.html">
              tree
            </A>
            
          
        </DIV>
    </DIV>
    
    <DIV ID="main-content">
  
  <H1 CLASS="pudge-member-page-heading">
    <TT>JSONDecoder</TT>
  </H1>
  <H4 CLASS="pudge-member-page-subheading">
    Simple JSON &lt;<A HREF="http://json.org" CLASS="reference">http://json.org</A>> decoder
  </H4>
  <P CLASS="pudge-member-parent-link">
    <SMALL>
    The JSONDecoder class is accessible via the
    <A HREF="module-simplejson.html">
      <TT>simplejson</TT>
    </A> module.
    </SMALL>
  </P>
  <DIV ID="pudge-section-nav">
  <UL>
    <LI>
      
      <SPAN CLASS="pudge-missing-section-link">
        Attributes
      </SPAN>
    </LI><LI>
      <A HREF="#methods" CLASS="pudge-section-link">
        Methods (3)
      </A>
      
    </LI>
    
    <LI>
      <A HREF="simplejson/decoder.py.html?f=196&amp;l=272#196" CLASS="pudge-section-link">
        Source
      </A>
    </LI>
  </UL>
  </DIV>
  <DIV STYLE="clear: left"></DIV>
  <DIV CLASS="rst pudge-module-doc">
    <P>Performs the following translations in decoding:</P>
<TABLE BORDER="1" CLASS="docutils">
<COLGROUP>
<COL WIDTH="44%">
<COL WIDTH="56%">
</COLGROUP>
<THEAD VALIGN="bottom">
<TR><TH CLASS="head">JSON</TH>
<TH CLASS="head">Python</TH>
</TR>
</THEAD>
<TBODY VALIGN="top">
<TR><TD>object</TD>
<TD>dict</TD>
</TR>
<TR><TD>array</TD>
<TD>list</TD>
</TR>
<TR><TD>string</TD>
<TD>unicode</TD>
</TR>
<TR><TD>number (int)</TD>
<TD>int, long</TD>
</TR>
<TR><TD>number (real)</TD>
<TD>float</TD>
</TR>
<TR><TD>true</TD>
<TD>True</TD>
</TR>
<TR><TD>false</TD>
<TD>False</TD>
</TR>
<TR><TD>null</TD>
<TD>None</TD>
</TR>
</TBODY>
</TABLE>
<P>It also understands <TT CLASS="docutils literal"><SPAN CLASS="pre">NaN</SPAN></TT>, <TT CLASS="docutils literal"><SPAN CLASS="pre">Infinity</SPAN></TT>, and <TT CLASS="docutils literal"><SPAN CLASS="pre">-Infinity</SPAN></TT> as
their corresponding <TT CLASS="docutils literal"><SPAN CLASS="pre">float</SPAN></TT> values, which is outside the JSON spec.</P>

  </DIV>
  
  <HR>
  
  
    <A NAME="methods"></A>
    <H2>Methods</H2>
    <DIV CLASS="pudge-member routine alias">
    <A NAME="__init__"></A>
    <H4 CLASS="pudge-member-name"><SPAN CLASS="prefix">f</SPAN>
      <TT><A HREF="class-simplejson.JSONDecoder.html#__init__" CLASS="pudge-obj-link">__init__</A>(self, encoding=None, object_hook=None)</TT>
      <A HREF="simplejson/decoder.py.html?f=229&amp;l=245#229" TITLE="View Source">...</A>
    </H4>
    <DIV CLASS="pudge-section rst">
      
    <P CLASS="pudge-member-blurb">
      <TT CLASS="docutils literal"><SPAN CLASS="pre">encoding</SPAN></TT> determines the encoding used to interpret any <TT CLASS="docutils literal"><SPAN CLASS="pre">str</SPAN></TT>
objects decoded by this instance (utf-8 by default).  It has no
effect when decoding <TT CLASS="docutils literal"><SPAN CLASS="pre">unicode</SPAN></TT> objects.
    </P>
    <P>Note that currently only encodings that are a superset of ASCII work,
strings of other encodings should be passed in as <TT CLASS="docutils literal"><SPAN CLASS="pre">unicode</SPAN></TT>.</P>
<P><TT CLASS="docutils literal"><SPAN CLASS="pre">object_hook</SPAN></TT>, if specified, will be called with the result
of every JSON object decoded and its return value will be used in
place of the given <TT CLASS="docutils literal"><SPAN CLASS="pre">dict</SPAN></TT>.  This can be used to provide custom
deserializations (e.g. to support JSON-RPC class hinting).</P>

  
    </DIV>
  </DIV><DIV CLASS="pudge-member routine alias">
    <A NAME="decode"></A>
    <H4 CLASS="pudge-member-name"><SPAN CLASS="prefix">f</SPAN>
      <TT><A HREF="class-simplejson.JSONDecoder.html#decode" CLASS="pudge-obj-link">decode</A>(self, s, _w=&lt;built-in method match of _sre.SRE_Pattern object at 0x13244a0>)</TT>
      <A HREF="simplejson/decoder.py.html?f=246&amp;l=256#246" TITLE="View Source">...</A>
    </H4>
    <DIV CLASS="pudge-section rst">
      
    <P CLASS="pudge-member-blurb">
      Return the Python representation of <TT CLASS="docutils literal"><SPAN CLASS="pre">s</SPAN></TT> (a <TT CLASS="docutils literal"><SPAN CLASS="pre">str</SPAN></TT> or <TT CLASS="docutils literal"><SPAN CLASS="pre">unicode</SPAN></TT>
instance containing a JSON document)
    </P>
    
  
    </DIV>
  </DIV><DIV CLASS="pudge-member routine alias">
    <A NAME="raw_decode"></A>
    <H4 CLASS="pudge-member-name"><SPAN CLASS="prefix">f</SPAN>
      <TT><A HREF="class-simplejson.JSONDecoder.html#raw_decode" CLASS="pudge-obj-link">raw_decode</A>(self, s, **kw)</TT>
      <A HREF="simplejson/decoder.py.html?f=257&amp;l=272#257" TITLE="View Source">...</A>
    </H4>
    <DIV CLASS="pudge-section rst">
      
    <P CLASS="pudge-member-blurb">
      Decode a JSON document from <TT CLASS="docutils literal"><SPAN CLASS="pre">s</SPAN></TT> (a <TT CLASS="docutils literal"><SPAN CLASS="pre">str</SPAN></TT> or <TT CLASS="docutils literal"><SPAN CLASS="pre">unicode</SPAN></TT> beginning
with a JSON document) and return a 2-tuple of the Python
representation and the index in <TT CLASS="docutils literal"><SPAN CLASS="pre">s</SPAN></TT> where the document ended.
    </P>
    <P>This can be used to decode a JSON document from a string that may
have extraneous data at the end.</P>

  
    </DIV>
  </DIV>
    
  
  
  <P>
    <SMALL>
    
    
    See 
    <A HREF="simplejson/decoder.py.html?f=196&amp;l=272#196" TITLE="simplejson/decoder.py:196">the source</A>
    for more information.
    </SMALL>
  </P>

</DIV>
    
    <DIV ID="footer">
      
      <P ID="pudge">
        Built with
        <A HREF="http://lesscode.org/projects/pudge/">
          Pudge/0.1.3</A>
      </P>

      
    </DIV>
    </DIV>
  </BODY>

</HTML>