当前位置: 首页>>代码示例>>C#>>正文


C# JsonObject.getJSONObject方法代码示例

本文整理汇总了C#中Jayrock.Json.JsonObject.getJSONObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.getJSONObject方法的具体用法?C# JsonObject.getJSONObject怎么用?C# JsonObject.getJSONObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jayrock.Json.JsonObject的用法示例。


在下文中一共展示了JsonObject.getJSONObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        /**
         * Processes a JSON request.
         *
         * @param request Original JSON request
         * @return The JSON response.
         */
        public JsonObject Process(JsonObject request)
        {
            JsonObject response = new JsonObject();

            JsonObject requestContext = request.getJSONObject("context");
            JsonArray requestedGadgets = request["gadgets"] as JsonArray;

            // Process all JSON first so that we don't wind up with hanging threads if
            // a JsonException is thrown.
            List<IAsyncResult> gadgets = new List<IAsyncResult>(requestedGadgets.Length);
            for (int i = 0, j = requestedGadgets.Length; i < j; ++i)
            {
                var context = new JsonRpcGadgetContext(requestContext, (JsonObject)requestedGadgets[i]);
                PreloadProcessor proc = new PreloadProcessor(CallJob);
                IAsyncResult result = proc.BeginInvoke(context, null, null);
                gadgets.Add(result);
            }

            foreach (var entry in gadgets)
            {
                try
                {
                    AsyncResult result = (AsyncResult)entry;
                    PreloadProcessor proc = (PreloadProcessor)result.AsyncDelegate;
                    JsonObject gadget = proc.EndInvoke(result);
                    response.Accumulate("gadgets", gadget);
                }
                catch (JsonException e)
                {
                    throw new RpcException("Unable to write JSON", e);
                }
                catch (Exception ee)
                {
                    if (!(ee is RpcException))
                    {
                        throw new RpcException("Processing interrupted", ee);
                    }
                    RpcException e = (RpcException)ee;
                    // Just one gadget failed; mark it as such.
                    try
                    {
                        GadgetContext context = e.Context;
                        
                        JsonObject errorObj = new JsonObject();
                        errorObj.Put("url", context.getUrl())
                            .Put("moduleId", context.getModuleId());
                        errorObj.Accumulate("errors", e.Message);
                        response.Accumulate("gadgets", errorObj);
                    }
                    catch (JsonException je)
                    {
                        throw new RpcException("Unable to write JSON", je);
                    }
                }
            }
            return response;
        }
开发者ID:s7loves,项目名称:pesta,代码行数:63,代码来源:JsonRpcHandler.cs

示例2: getEntryObject

  /**
   * Inspects the passed object for one of several specific properties and, if
   * found, returns that property as a JsonObject object. All valid response
   * objects which encapsulate a single data item (e.g. a person) must have
   * this property.
   * 
   * @param  root JsonObject to query for the presence of the specific property
   * @throws OpenSocialRequestException if property is not found _in the passed
   *         object
   * @throws JSONException
   */
  private static JsonObject getEntryObject(JsonObject root)
    {

    JsonObject entry = new JsonObject();

    if (root.Contains("data")) {
      entry = root.getJSONObject("data");
    } else if (root.Contains("entry")) {
      entry = root.getJSONObject("entry");
    } else {
      throw new OpenSocialRequestException("Entry not found");
    }

    return entry;
  }
开发者ID:s7loves,项目名称:pesta,代码行数:26,代码来源:OpenSocialJsonParser.cs

示例3: createObjectRepresentation

  /**
   * Recursively iterates through the properties of the passed JsonObject
   * object and returns a Map of OpenSocialField objects keyed on Strings
   * representing the property values and names respectively.
   * 
   * @param  o Object-oriented representation of a JSON object which is
   *         transformed into and returned as a Map of OpenSocialField
   *         objects keyed on Strings
   * @throws JSONException
   */
  private static Dictionary<String, OpenSocialField> createObjectRepresentation(
      JsonObject o)
    {

    Dictionary<String,OpenSocialField> r = new Dictionary<String,OpenSocialField>();

    var keys = o.Names;

      foreach (string key in keys)
      {
        String property = o[key].ToString();

      if (property.Length > 0 && property[0] == '{') {
        JsonObject p = o.getJSONObject(key);
        OpenSocialField field = new OpenSocialField(true);

        field.addValue(new OpenSocialObject(createObjectRepresentation(p)));
        r.Add(key, field);
      } else if (property.Length > 0 && property[0] == '[') {
        JsonArray p = (JsonArray)o[key];
        var values = createArrayRepresentation(p);
        OpenSocialField field = new OpenSocialField(true);

        foreach(var v in values) {
          field.addValue(v);
        }

        r.Add(key, field);
      } else if (property.Length > 0) {
        OpenSocialField field = new OpenSocialField(false);
        field.addValue(unescape(property));
        r.Add(key, field);
      }      
    }

    return r;
  }
开发者ID:s7loves,项目名称:pesta,代码行数:47,代码来源:OpenSocialJsonParser.cs

示例4: getEntryArray

  /**
   * Inspects the passed object for one of several specific properties and, if
   * found, returns that property as a JsonArray object. All valid response
   * objects which contain a data collection (e.g. a collection of people)
   * must have this property.
   * 
   * @param  root JsonObject to query for the presence of the specific property
   * @throws OpenSocialRequestException if property is not found _in the passed
   *         object
   * @throws JSONException
   */
  private static JsonArray getEntryArray(JsonObject root)
    {

    JsonArray entry = new JsonArray();

    if (root.Contains("entry")) {
      entry = (JsonArray)root["entry"];
    } else if (root.Contains("data")) {
      entry = (JsonArray)root.getJSONObject("data")["list"];
    } else {
      throw new OpenSocialRequestException("Entry not found");
    }

    return entry;
  }
开发者ID:s7loves,项目名称:pesta,代码行数:26,代码来源:OpenSocialJsonParser.cs


注:本文中的Jayrock.Json.JsonObject.getJSONObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。