Пример #1
0
		/*
		Copyright (c) 2002 JSON.org
		
		Permission is hereby granted, free of charge, to any person obtaining a copy
		of this software and associated documentation files (the "Software"), to deal
		in the Software without restriction, including without limitation the rights
		to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
		copies of the Software, and to permit persons to whom the Software is
		furnished to do so, subject to the following conditions:
		
		The above copyright notice and this permission notice shall be included in all
		copies or substantial portions of the Software.
		
		The Software shall be used for Good, not Evil.
		
		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
		SOFTWARE.
		*/
		/// <summary>Convert an HTTP header string into a JSONObject.</summary>
		/// <remarks>
		/// Convert an HTTP header string into a JSONObject. It can be a request
		/// header or a response header. A request header will contain
		/// <pre>{
		/// Method: "POST" (for example),
		/// "Request-URI": "/" (for example),
		/// "HTTP-Version": "HTTP/1.1" (for example)
		/// }</pre>
		/// A response header will contain
		/// <pre>{
		/// "HTTP-Version": "HTTP/1.1" (for example),
		/// "Status-Code": "200" (for example),
		/// "Reason-Phrase": "OK" (for example)
		/// }</pre>
		/// In addition, the other parameters in the header will be captured, using
		/// the HTTP field names as JSON names, so that <pre>
		/// Date: Sun, 26 May 2002 18:06:04 GMT
		/// Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
		/// Cache-Control: no-cache</pre>
		/// become
		/// <pre>{...
		/// Date: "Sun, 26 May 2002 18:06:04 GMT",
		/// Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
		/// "Cache-Control": "no-cache",
		/// ...}</pre>
		/// It does no further checking or conversion. It does not parse dates.
		/// It does not do '%' transforms on URLs.
		/// </remarks>
		/// <param name="string">An HTTP header string.</param>
		/// <returns>
		/// A JSONObject containing the elements and attributes
		/// of the XML string.
		/// </returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static org.json.JSONObject ToJSONObject(string @string)
		{
			org.json.JSONObject jo = new org.json.JSONObject();
			org.json.HTTPTokener x = new org.json.HTTPTokener(@string);
			string token;
			token = x.NextToken();
			if (token.ToUpper().StartsWith("HTTP"))
			{
				// Response
				jo.Put("HTTP-Version", token);
				jo.Put("Status-Code", x.NextToken());
				jo.Put("Reason-Phrase", x.NextTo('\0'));
				x.Next();
			}
			else
			{
				// Request
				jo.Put("Method", token);
				jo.Put("Request-URI", x.NextToken());
				jo.Put("HTTP-Version", x.NextToken());
			}
			// Fields
			while (x.More())
			{
				string name = x.NextTo(':');
				x.Next(':');
				jo.Put(name, x.NextTo('\0'));
				x.Next();
			}
			return jo;
		}
Пример #2
0
            /// <summary>
            /// Callback to implement in your app to handle when a notification is opened from the Android status bar or
            /// a new one comes in while the app is running.
            /// This method is located in this activity as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
            /// </summary>
            /// <param name="message">        The message string the user seen/should see in the Android status bar. </param>
            /// <param name="additionalData"> The additionalData key value pair section you entered in on onesignal.com. </param>
            /// <param name="isActive">       Was the app in the foreground when the notification was received. </param>
            public override void notificationOpened(string message, JSONObject additionalData, bool isActive)
            {
                string messageTitle = "OneSignal Example", messageBody = message;

                try
                {
                    if (additionalData != null)
                    {
                        if (additionalData.has("title"))
                        {
                            messageTitle = additionalData.getString("title");
                        }
                        if (additionalData.has("actionSelected"))
                        {
                            messageBody += "\nPressed ButtonID: " + additionalData.getString("actionSelected");
                        }

                        messageBody = message + "\n\nFull additionalData:\n" + additionalData.ToString();
                    }
                }
                catch (JSONException)
                {
                }

                (new AlertDialog.Builder(MainActivity.currentActivity)).setTitle(messageTitle).setMessage(messageBody).setCancelable(true).setPositiveButton("OK", null).create().show();
            }
Пример #3
0
		  /// <summary>
		  /// Callback to implement in your app to handle when a notification is opened from the Android status bar or
		  /// a new one comes in while the app is running.
		  /// This method is located in this activity as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
		  /// </summary>
		  /// <param name="message">        The message string the user seen/should see in the Android status bar. </param>
		  /// <param name="additionalData"> The additionalData key value pair section you entered in on onesignal.com. </param>
		  /// <param name="isActive">       Was the app in the foreground when the notification was received. </param>
		  public override void notificationOpened(string message, JSONObject additionalData, bool isActive)
		  {
			 string messageTitle = "OneSignal Example", messageBody = message;

			 try
			 {
				if (additionalData != null)
				{
				   if (additionalData.has("title"))
				   {
					  messageTitle = additionalData.getString("title");
				   }
				   if (additionalData.has("actionSelected"))
				   {
					  messageBody += "\nPressed ButtonID: " + additionalData.getString("actionSelected");
				   }

				   messageBody = message + "\n\nFull additionalData:\n" + additionalData.ToString();
				}
			 }
			 catch (JSONException)
			 {
			 }

			 (new AlertDialog.Builder(MainActivity.currentActivity)).setTitle(messageTitle).setMessage(messageBody).setCancelable(true).setPositiveButton("OK", null).create().show();
		  }
		/*
		Copyright (c) 2002 JSON.org
		
		Permission is hereby granted, free of charge, to any person obtaining a copy
		of this software and associated documentation files (the "Software"), to deal
		in the Software without restriction, including without limitation the rights
		to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
		copies of the Software, and to permit persons to whom the Software is
		furnished to do so, subject to the following conditions:
		
		The above copyright notice and this permission notice shall be included in all
		copies or substantial portions of the Software.
		
		The Software shall be used for Good, not Evil.
		
		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
		SOFTWARE.
		*/
		/// <summary>Convert a cookie list into a JSONObject.</summary>
		/// <remarks>
		/// Convert a cookie list into a JSONObject. A cookie list is a sequence
		/// of name/value pairs. The names are separated from the values by '='.
		/// The pairs are separated by ';'. The names and the values
		/// will be unescaped, possibly converting '+' and '%' sequences.
		/// To add a cookie to a cooklist,
		/// cookielistJSONObject.put(cookieJSONObject.getString("name"),
		/// cookieJSONObject.getString("value"));
		/// </remarks>
		/// <param name="string">A cookie list string</param>
		/// <returns>A JSONObject</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static org.json.JSONObject ToJSONObject(string @string)
		{
			org.json.JSONObject jo = new org.json.JSONObject();
			org.json.JSONTokener x = new org.json.JSONTokener(@string);
			while (x.More())
			{
				string name = org.json.Cookie.Unescape(x.NextTo('='));
				x.Next('=');
				jo.Put(name, org.json.Cookie.Unescape(x.NextTo(';')));
				x.Next();
			}
			return jo;
		}
		/*
		Copyright (c) 2002 JSON.org
		
		Permission is hereby granted, free of charge, to any person obtaining a copy
		of this software and associated documentation files (the "Software"), to deal
		in the Software without restriction, including without limitation the rights
		to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
		copies of the Software, and to permit persons to whom the Software is
		furnished to do so, subject to the following conditions:
		
		The above copyright notice and this permission notice shall be included in all
		copies or substantial portions of the Software.
		
		The Software shall be used for Good, not Evil.
		
		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
		SOFTWARE.
		*/
		/// <summary>Converts a property file object into a JSONObject.</summary>
		/// <remarks>Converts a property file object into a JSONObject. The property file object is a table of name value pairs.</remarks>
		/// <param name="properties">java.util.Properties</param>
		/// <returns>JSONObject</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static org.json.JSONObject ToJSONObject(java.util.Properties properties)
		{
			org.json.JSONObject jo = new org.json.JSONObject();
			if (properties != null && !properties.IsEmpty())
			{
				java.util.Enumeration<object> enumProperties = properties.PropertyNames();
				while (enumProperties.MoveNext())
				{
					string name = (string)enumProperties.Current;
					jo.Put(name, properties.GetProperty(name));
				}
			}
			return jo;
		}
Пример #6
0
        /// <summary> Constructor.</summary>
        /// <param name="filePath">- the file path of the plug-in configuration file
        /// </param>
        /// <throws>  JSONException </throws>
        /// <throws>  IOException </throws>
        public JSONReader(System.String filePath)
        {
            System.IO.StreamReader    reader = new System.IO.StreamReader(filePath, System.Text.Encoding.UTF8);
            System.Text.StringBuilder buf    = new System.Text.StringBuilder();
            char[] cbuf = new char[4096];
            int    idx  = 0;

            while ((idx = reader.Read((System.Char[])cbuf, 0, cbuf.Length)) > 1)
            {
                buf.Append(cbuf, 0, idx);
            }
            json = new JSONObject(buf.ToString());

            reader.Close();
        }
Пример #7
0
        /// <summary> Constructor.</summary>
        /// <param name="filePath">- the file path of the plug-in configuration file
        /// </param>
        /// <throws>  JSONException </throws>
        /// <throws>  IOException </throws>
        public JSONReader(System.String filePath)
        {
            System.IO.StreamReader reader = new System.IO.StreamReader(filePath, System.Text.Encoding.UTF8);
            System.Text.StringBuilder buf = new System.Text.StringBuilder();
            char[] cbuf = new char[4096];
            int idx = 0;

            while ((idx = reader.Read((System.Char[]) cbuf, 0, cbuf.Length)) > 1)
            {
                buf.Append(cbuf, 0, idx);
            }
            json = new JSONObject(buf.ToString());

            reader.Close();
        }
Пример #8
0
        /// <summary>
        /// Parse a campaign. </summary>
        /// <param name="campaignId"> already parsed campaign id. </param>
        /// <param name="values"> content data. </param>
        /// <exception cref="JSONException"> if payload parsing failure. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: EngagementReachContent(CampaignId campaignId, android.content.ContentValues values) throws org.json.JSONException
        internal EngagementReachContent(CampaignId campaignId, ContentValues values)
        {
            /* Parse base fields */
            mCampaignId = campaignId;
            mDlc        = values.getAsInteger(DLC);
            mDlcId      = values.getAsString(DLC_ID);
            mCategory   = values.getAsString(CATEGORY);
            long?expiry = values.getAsLong(TTL);

            if (expiry != null)
            {
                expiry *= 1000L;
                if (parseBoolean(values, USER_TIME_ZONE))
                {
                    expiry -= TimeZone.Default.getOffset(expiry);
                }
            }
            mExpiry = expiry;
            if (values.containsKey(PAYLOAD))
            {
                Payload = new JSONObject(values.getAsString(PAYLOAD));
            }
        }
Пример #9
0
		/// <summary>
		/// Convert a well-formed (but not necessarily valid) XML string into a
		/// JSONObject.
		/// </summary>
		/// <remarks>
		/// Convert a well-formed (but not necessarily valid) XML string into a
		/// JSONObject. Some information may be lost in this transformation
		/// because JSON is a data format and XML is a document format. XML uses
		/// elements, attributes, and content text, while JSON uses unordered
		/// collections of name/value pairs and arrays of values. JSON does not
		/// does not like to distinguish between elements and attributes.
		/// Sequences of similar elements are represented as JSONArrays. Content
		/// text may be placed in a "content" member. Comments, prologs, DTDs, and
		/// <code>&lt;[ [ ]]&gt;</code> are ignored.
		/// </remarks>
		/// <param name="string">The source string.</param>
		/// <returns>A JSONObject containing the structured data from the XML string.</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static org.json.JSONObject ToJSONObject(string @string)
		{
			org.json.JSONObject jo = new org.json.JSONObject();
			org.json.XMLTokener x = new org.json.XMLTokener(@string);
			while (x.More() && x.SkipPast("<"))
			{
				Parse(x, jo, null);
			}
			return jo;
		}
Пример #10
0
		/// <summary>Scan the content following the named tag, attaching it to the context.</summary>
		/// <param name="x">The XMLTokener containing the source string.</param>
		/// <param name="context">The JSONObject that will include the new material.</param>
		/// <param name="name">The tag name.</param>
		/// <returns>true if the close tag is processed.</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		private static bool Parse(org.json.XMLTokener x, org.json.JSONObject context, string name)
		{
			char c;
			int i;
			org.json.JSONObject jsonobject = null;
			string @string;
			string tagName;
			object token;
			// Test for and skip past these forms:
			//      <!-- ... -->
			//      <!   ...   >
			//      <![  ... ]]>
			//      <?   ...  ?>
			// Report errors for these forms:
			//      <>
			//      <=
			//      <<
			token = x.NextToken();
			// <!
			if (token == BANG)
			{
				c = x.Next();
				if (c == '-')
				{
					if (x.Next() == '-')
					{
						x.SkipPast("-->");
						return false;
					}
					x.Back();
				}
				else
				{
					if (c == '[')
					{
						token = x.NextToken();
						if ("CDATA".Equals(token))
						{
							if (x.Next() == '[')
							{
								@string = x.NextCDATA();
								if (@string.Length > 0)
								{
									context.Accumulate("content", @string);
								}
								return false;
							}
						}
						throw x.SyntaxError("Expected 'CDATA['");
					}
				}
				i = 1;
				do
				{
					token = x.NextMeta();
					if (token == null)
					{
						throw x.SyntaxError("Missing '>' after '<!'.");
					}
					else
					{
						if (token == LT)
						{
							i += 1;
						}
						else
						{
							if (token == GT)
							{
								i -= 1;
							}
						}
					}
				}
				while (i > 0);
				return false;
			}
			else
			{
				if (token == QUEST)
				{
					// <?
					x.SkipPast("?>");
					return false;
				}
				else
				{
					if (token == SLASH)
					{
						// Close tag </
						token = x.NextToken();
						if (name == null)
						{
							throw x.SyntaxError("Mismatched close tag " + token);
						}
						if (!token.Equals(name))
						{
							throw x.SyntaxError("Mismatched " + name + " and " + token);
						}
						if (x.NextToken() != GT)
						{
							throw x.SyntaxError("Misshaped close tag");
						}
						return true;
					}
					else
					{
						if (token is char)
						{
							throw x.SyntaxError("Misshaped tag");
						}
						else
						{
							// Open tag <
							tagName = (string)token;
							token = null;
							jsonobject = new org.json.JSONObject();
							for (; ; )
							{
								if (token == null)
								{
									token = x.NextToken();
								}
								// attribute = value
								if (token is string)
								{
									@string = (string)token;
									token = x.NextToken();
									if (token == EQ)
									{
										token = x.NextToken();
										if (!(token is string))
										{
											throw x.SyntaxError("Missing value");
										}
										jsonobject.Accumulate(@string, org.json.XML.StringToValue((string)token));
										token = null;
									}
									else
									{
										jsonobject.Accumulate(@string, string.Empty);
									}
								}
								else
								{
									// Empty tag <.../>
									if (token == SLASH)
									{
										if (x.NextToken() != GT)
										{
											throw x.SyntaxError("Misshaped tag");
										}
										if (jsonobject.Length() > 0)
										{
											context.Accumulate(tagName, jsonobject);
										}
										else
										{
											context.Accumulate(tagName, string.Empty);
										}
										return false;
									}
									else
									{
										// Content, between <...> and </...>
										if (token == GT)
										{
											for (; ; )
											{
												token = x.NextContent();
												if (token == null)
												{
													if (tagName != null)
													{
														throw x.SyntaxError("Unclosed tag " + tagName);
													}
													return false;
												}
												else
												{
													if (token is string)
													{
														@string = (string)token;
														if (@string.Length > 0)
														{
															jsonobject.Accumulate("content", org.json.XML.StringToValue(@string));
														}
													}
													else
													{
														// Nested element
														if (token == LT)
														{
															if (Parse(x, jsonobject, tagName))
															{
																if (jsonobject.Length() == 0)
																{
																	context.Accumulate(tagName, string.Empty);
																}
																else
																{
																	if (jsonobject.Length() == 1 && jsonobject.Opt("content") != null)
																	{
																		context.Accumulate(tagName, jsonobject.Opt("content"));
																	}
																	else
																	{
																		context.Accumulate(tagName, jsonobject);
																	}
																}
																return false;
															}
														}
													}
												}
											}
										}
										else
										{
											throw x.SyntaxError("Misshaped tag");
										}
									}
								}
							}
						}
					}
				}
			}
		}
Пример #11
0
		/*
		Copyright (c) 2008 JSON.org
		
		Permission is hereby granted, free of charge, to any person obtaining a copy
		of this software and associated documentation files (the "Software"), to deal
		in the Software without restriction, including without limitation the rights
		to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
		copies of the Software, and to permit persons to whom the Software is
		furnished to do so, subject to the following conditions:
		
		The above copyright notice and this permission notice shall be included in all
		copies or substantial portions of the Software.
		
		The Software shall be used for Good, not Evil.
		
		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
		IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
		FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
		AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
		LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
		OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
		SOFTWARE.
		*/
		/// <summary>Parse XML values and store them in a JSONArray.</summary>
		/// <param name="x">The XMLTokener containing the source string.</param>
		/// <param name="arrayForm">true if array form, false if object form.</param>
		/// <param name="ja">
		/// The JSONArray that is containing the current tag or null
		/// if we are at the outermost level.
		/// </param>
		/// <returns>A JSONArray if the value is the outermost tag, otherwise null.</returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		private static object Parse(org.json.XMLTokener x, bool arrayForm, org.json.JSONArray ja)
		{
			string attribute;
			char c;
			string closeTag = null;
			int i;
			org.json.JSONArray newja = null;
			org.json.JSONObject newjo = null;
			object token;
			string tagName = null;
			// Test for and skip past these forms:
			//      <!-- ... -->
			//      <![  ... ]]>
			//      <!   ...   >
			//      <?   ...  ?>
			while (true)
			{
				if (!x.More())
				{
					throw x.SyntaxError("Bad XML");
				}
				token = x.NextContent();
				if (token == org.json.XML.LT)
				{
					token = x.NextToken();
					if (token is char)
					{
						if (token == org.json.XML.SLASH)
						{
							// Close tag </
							token = x.NextToken();
							if (!(token is string))
							{
								throw new org.json.JSONException("Expected a closing name instead of '" + token + "'.");
							}
							if (x.NextToken() != org.json.XML.GT)
							{
								throw x.SyntaxError("Misshaped close tag");
							}
							return token;
						}
						else
						{
							if (token == org.json.XML.BANG)
							{
								// <!
								c = x.Next();
								if (c == '-')
								{
									if (x.Next() == '-')
									{
										x.SkipPast("-->");
									}
									else
									{
										x.Back();
									}
								}
								else
								{
									if (c == '[')
									{
										token = x.NextToken();
										if (token.Equals("CDATA") && x.Next() == '[')
										{
											if (ja != null)
											{
												ja.Put(x.NextCDATA());
											}
										}
										else
										{
											throw x.SyntaxError("Expected 'CDATA['");
										}
									}
									else
									{
										i = 1;
										do
										{
											token = x.NextMeta();
											if (token == null)
											{
												throw x.SyntaxError("Missing '>' after '<!'.");
											}
											else
											{
												if (token == org.json.XML.LT)
												{
													i += 1;
												}
												else
												{
													if (token == org.json.XML.GT)
													{
														i -= 1;
													}
												}
											}
										}
										while (i > 0);
									}
								}
							}
							else
							{
								if (token == org.json.XML.QUEST)
								{
									// <?
									x.SkipPast("?>");
								}
								else
								{
									throw x.SyntaxError("Misshaped tag");
								}
							}
						}
					}
					else
					{
						// Open tag <
						if (!(token is string))
						{
							throw x.SyntaxError("Bad tagName '" + token + "'.");
						}
						tagName = (string)token;
						newja = new org.json.JSONArray();
						newjo = new org.json.JSONObject();
						if (arrayForm)
						{
							newja.Put(tagName);
							if (ja != null)
							{
								ja.Put(newja);
							}
						}
						else
						{
							newjo.Put("tagName", tagName);
							if (ja != null)
							{
								ja.Put(newjo);
							}
						}
						token = null;
						for (; ; )
						{
							if (token == null)
							{
								token = x.NextToken();
							}
							if (token == null)
							{
								throw x.SyntaxError("Misshaped tag");
							}
							if (!(token is string))
							{
								break;
							}
							// attribute = value
							attribute = (string)token;
							if (!arrayForm && ("tagName".Equals(attribute) || "childNode".Equals(attribute)))
							{
								throw x.SyntaxError("Reserved attribute.");
							}
							token = x.NextToken();
							if (token == org.json.XML.EQ)
							{
								token = x.NextToken();
								if (!(token is string))
								{
									throw x.SyntaxError("Missing value");
								}
								newjo.Accumulate(attribute, org.json.XML.StringToValue((string)token));
								token = null;
							}
							else
							{
								newjo.Accumulate(attribute, string.Empty);
							}
						}
						if (arrayForm && newjo.Length() > 0)
						{
							newja.Put(newjo);
						}
						// Empty tag <.../>
						if (token == org.json.XML.SLASH)
						{
							if (x.NextToken() != org.json.XML.GT)
							{
								throw x.SyntaxError("Misshaped tag");
							}
							if (ja == null)
							{
								if (arrayForm)
								{
									return newja;
								}
								else
								{
									return newjo;
								}
							}
						}
						else
						{
							// Content, between <...> and </...>
							if (token != org.json.XML.GT)
							{
								throw x.SyntaxError("Misshaped tag");
							}
							closeTag = (string)Parse(x, arrayForm, newja);
							if (closeTag != null)
							{
								if (!closeTag.Equals(tagName))
								{
									throw x.SyntaxError("Mismatched '" + tagName + "' and '" + closeTag + "'");
								}
								tagName = null;
								if (!arrayForm && newja.Length() > 0)
								{
									newjo.Put("childNodes", newja);
								}
								if (ja == null)
								{
									if (arrayForm)
									{
										return newja;
									}
									else
									{
										return newjo;
									}
								}
							}
						}
					}
				}
				else
				{
					if (ja != null)
					{
						ja.Put(token is string ? org.json.XML.StringToValue((string)token) : token);
					}
				}
			}
		}
	  /// <summary>
	  /// Parse a campaign. </summary>
	  /// <param name="campaignId"> already parsed campaign id. </param>
	  /// <param name="values"> content data. </param>
	  /// <exception cref="JSONException"> if payload parsing failure. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: EngagementReachContent(CampaignId campaignId, android.content.ContentValues values) throws org.json.JSONException
	  internal EngagementReachContent(CampaignId campaignId, ContentValues values)
	  {
		/* Parse base fields */
		mCampaignId = campaignId;
		mDlc = values.getAsInteger(DLC);
		mDlcId = values.getAsString(DLC_ID);
		mCategory = values.getAsString(CATEGORY);
		long? expiry = values.getAsLong(TTL);
		if (expiry != null)
		{
		  expiry *= 1000L;
		  if (parseBoolean(values, USER_TIME_ZONE))
		  {
			expiry -= TimeZone.Default.getOffset(expiry);
		  }
		}
		mExpiry = expiry;
		if (values.containsKey(PAYLOAD))
		{
		  Payload = new JSONObject(values.getAsString(PAYLOAD));
		}
	  }
Пример #13
0
 internal JSONObjectEnumerator(org.json.JSONObject jsonObject)
 {
     m_bStarted     = false;
     m_currentIndex = -1;
     m_jsonObject   = jsonObject;
 }
		/// <summary>Construct a JSONObject from a ResourceBundle.</summary>
		/// <param name="baseName">The ResourceBundle base name.</param>
		/// <param name="locale">The Locale to load the ResourceBundle for.</param>
		/// <exception cref="JSONException">If any JSONExceptions are detected.</exception>
		/// <exception cref="org.json.JSONException"/>
		public JSONObject(string baseName, System.Globalization.CultureInfo locale)
			: this()
		{
			java.util.ResourceBundle bundle = java.util.ResourceBundle.GetBundle(baseName, locale, java.lang.Thread.CurrentThread().GetContextClassLoader());
			// Iterate through the keys in the bundle.
			java.util.Enumeration<string> keys = bundle.GetKeys();
			while (keys.MoveNext())
			{
				object key = keys.Current;
				if (key != null)
				{
					// Go through the path, ensuring that there is a nested JSONObject for each
					// segment except the last. Add the value using the last segment's name into
					// the deepest nested JSONObject.
					string[] path = ((string)key).Split("\\.");
					int last = path.Length - 1;
					org.json.JSONObject target = this;
					for (int i = 0; i < last; i += 1)
					{
						string segment = path[i];
						org.json.JSONObject nextTarget = target.OptJSONObject(segment);
						if (nextTarget == null)
						{
							nextTarget = new org.json.JSONObject();
							target.Put(segment, nextTarget);
						}
						target = nextTarget;
					}
					target.Put(path[last], bundle.GetString((string)key));
				}
			}
		}
Пример #15
0
		/// <summary>Convert a cookie specification string into a JSONObject.</summary>
		/// <remarks>
		/// Convert a cookie specification string into a JSONObject. The string
		/// will contain a name value pair separated by '='. The name and the value
		/// will be unescaped, possibly converting '+' and '%' sequences. The
		/// cookie properties may follow, separated by ';', also represented as
		/// name=value (except the secure property, which does not have a value).
		/// The name will be stored under the key "name", and the value will be
		/// stored under the key "value". This method does not do checking or
		/// validation of the parameters. It only converts the cookie string into
		/// a JSONObject.
		/// </remarks>
		/// <param name="string">The cookie specification string.</param>
		/// <returns>
		/// A JSONObject containing "name", "value", and possibly other
		/// members.
		/// </returns>
		/// <exception cref="JSONException"/>
		/// <exception cref="org.json.JSONException"/>
		public static org.json.JSONObject ToJSONObject(string @string)
		{
			string name;
			org.json.JSONObject jo = new org.json.JSONObject();
			object value;
			org.json.JSONTokener x = new org.json.JSONTokener(@string);
			jo.Put("name", x.NextTo('='));
			x.Next('=');
			jo.Put("value", x.NextTo(';'));
			x.Next();
			while (x.More())
			{
				name = Unescape(x.NextTo("=;"));
				if (x.Next() != '=')
				{
					if (name.Equals("secure"))
					{
						value = true;
					}
					else
					{
						throw x.SyntaxError("Missing '=' in cookie parameter.");
					}
				}
				else
				{
					value = Unescape(x.NextTo(';'));
					x.Next();
				}
				jo.Put(name, value);
			}
			return jo;
		}