Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 26, 2014 @ 14:16
    Kim Andersen
    1

    Error getting JSON CheckBox Picker to work

    Hi all

    I've installed this great package on a fresh Umbraco v7.1.8.

    So far I've used the XML CheckBox Picker with content, for users to pick categories from nodes in the content tree. Works perfect.

    Now I have to render some checkbox lists with data from a service returning JSON. So I made a new data type using the JSON CheckBox Picker.

    But unfortunately I'm not getting anything in return in the data type. In my concole I'm getting an error when calling: "http://myproject.local/umbraco/backoffice/nuPickers/JsonDataSourceApi/GetEditorDataItems?contextId=1078&propertyAlias=jsonPicker" saying:

    )]}',
    {"Message":"The requested resource does not support http method 'GET'."}
    

    I've tried with both a local json-file and with the URL to the service that provides me with the real JSON. My local json file looks like this:

    [
      {
        "TypeName": "Apple",
        "TypeId": "13"
      },
      { 
        "TypeName": "Lemon",
        "TypeId": "7"
      }
    ]
    

    But unfortunately I'm still getting the error :(

    In the "Key JSONPath" I have the following: TypeId and in the "Label JSONPath" I have the TypeName

    Anyone knows what I have to do to get It working?

    Thanks in advance.

    /Kim A

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Nov 26, 2014 @ 17:02
    Hendy Racher
    0

    Hi Kim,

    What value do you have configured for the url, and does this respond correctly with JSON ?

    Just a thought, but If it's a remote url, can the server resolve it correctly ?

    Hendy

  • Kim Andersen 1447 posts 2197 karma points MVP
    Nov 26, 2014 @ 21:12
    Kim Andersen
    0

    Hi Hendy

    Just for testing purpose I tried placing the js-file containing the JSON array in the root of the website, so in the url i had tried both of these paths:

    ~/json.json

    http://myproject.local/json.json

    But I'm getting the samme error either way.

    In the JSONPath property i have the following: $..*

    Don't know if that helps? Or you need to know anything else about the setup?

    /Kim A

  • Emil Christiansen 66 posts 148 karma points
    Nov 27, 2014 @ 14:24
    Emil Christiansen
    0

    Hi Hendy

    I have also tested the above - but keep getting this error:

    )]}', {"Message":"The requested resource does not support http method 'GET'."}

    I am trying to fetch json data via an external web-api service (which we also have implemented ourselves). CORS is enabled on the service and tested to be ok. The controller should respond to both GET and POST. The service returns this:

    [{"TypeId":"e577edb4-59a2-461d-9445-0e98b899233f","TypeName":"Test"}, {"TypeId":"bf920195-04f2-4e01-8d24-1ee0b26cedaf","TypeName":"Test text"}, {"TypeId":"61872f35-dcd3-4106-a20d-517e6c68550a","TypeName":"Hurray"}, {"TypeId":"bb7972d0-1eb5-47ff-9127-9dd595db342f","TypeName":"Not working"}, {"TypeId":"e39fbcba-473e-4b9c-a068-a96b3d5eabd1","TypeName":"Testing"}, {"TypeId":"a98283f1-c301-482f-bf68-ec2d19a3ad6e","TypeName":"Herro"}]

    The json should be valid.

    The datatype uses the custom editor "nuPicker:json checkbox picker" and is configured as follows:

    URL: http://myservice.local/api/GetAllTypes
    JSONPath: $..*
    Key JSONPath: TypeId
    Value JSONPath: TypeName
    

    I have tried on a clean Umbraco v 7.1.8 but the error is the same and like Kim i get can see this error in the console:

    http://myservice.local/umbraco/backoffice/nuPickers/JsonDataSourceApi/GetEditorDataItems?contextId=1078&propertyAlias=jsonPicker
    Failed to load resource: the server responded with a status of 500 (Internal Server Error) 
    

    Am i doing something completely wrong here or?

    Thanks in advance!

    /Emil

  • Zac 223 posts 575 karma points
    Jan 22, 2015 @ 11:45
    Zac
    0

    Same exact issue here

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jan 22, 2015 @ 11:58
    Hendy Racher
    0

    Hi Zac, any chance you would be able to debug to pinpoint a more spcific error ? (I'm wondering if the GetContents(string url) method in JsonDataSource.cs is working correctly)

  • Zac 223 posts 575 karma points
    Jan 22, 2015 @ 13:30
    Zac
    1

    Hi Hendy.

    We just spent a good hour trying every combination of JSONPath, Key and Label.

    The 500 error comes up as soon as you touch the node with the property on it. The error looks like this, regardless of what you put into the settings for the data type:

    )]}', {"Message":"An error has occurred.","ExceptionMessage":"Error reading string. Unexpected token: StartObject. Path '[0]', line 1, position 2.","ExceptionType":"Newtonsoft.Json.JsonReaderException","StackTrace":" at Newtonsoft.Json.JsonReader.ReadAsStringInternal()\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)\r\n at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)\r\n at Newtonsoft.Json.Linq.JToken.ToObject[T]()\r\n at nuPickers.Shared.JsonDataSource.JsonDataSource.GetEditorDataItems(Int32 contextId)\r\n at nuPickers.Shared.JsonDataSource.JsonDataSourceApiController.GetEditorDataItems(Int32 contextId, String propertyAlias, Object data)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func1 func, CancellationToken cancellationToken)"}

    That is the response from /umbraco/backoffice/nuPickers/JsonDataSourceApi/GetEditorDataItems?contextId=1060&propertyAlias=pickertest

    The only way I've been able to get this picker working was with a simple Array of strings for the JSON object, and blank key/label settings.

    Separate note - using ~/ does not work unless you are referencing the file system. Maybe this is intended but it took me a while to realise that I couldn't use ~/ for a relative URL as the field description does explicitly say "relative url".

    I really hope we can solve this as the tool looks like it will be seriously amazing.

  • Zac 223 posts 575 karma points
    Jan 22, 2015 @ 13:41
    Zac
    1

    Also, for sanity and future reference, let's say we're using the following JSON:

    http://beta.json-generator.com/KapqN6a

    [
      {
        "ItemId": 0,
        "Description": "ea"
      },
      {
        "ItemId": 1,
        "Description": "incididunt"
      },
      {
        "ItemId": 2,
        "Description": "qui"
      },
      {
        "ItemId": 3,
        "Description": "esse"
      },
      {
        "ItemId": 4,
        "Description": "irure"
      }
    ]
    
  • Zac 223 posts 575 karma points
    Jan 26, 2015 @ 11:17
    Zac
    0

    Hi again Hendy,

    Do you think you could let me know whether you think this is an issue you'll be able to look into any time soon?

    Totally understand if you can't get around to it, I'd just like to know whether to expect a solution during the project I'm currently working on! If not I can probably use the DotNet data source instead :)

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jan 26, 2015 @ 11:28
    Hendy Racher
    0

    Hi Zac, I started looking into this yesterday - I think the issue might be in the GetContents() method in https://github.com/uComponents/nuPickers/blob/master/source/nuPickers/Shared/JsonDataSource/JsonDataSource.cs

  • Zac 223 posts 575 karma points
    Jan 26, 2015 @ 12:13
    Zac
    1

    I'm guessing you meant the GetEditorDataItems method? Although I can see why we were having the relative url issues in GetContents():

    private static string GetContents(string url)
    {
        using (WebClient client = new WebClient())
        {
            if (url.StartsWith("~/"))
            {
                url = HttpContext.Current.Server.MapPath(url);
            }
    
            return client.DownloadString(url);
        }
    }
    

    E.g. maybe it should be something like url = url.Replace("~/", HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)) + "/")

  • RnrGfx 3 posts 27 karma points
    Feb 04, 2015 @ 10:28
    RnrGfx
    0

    I was using XML checkboxpicker, and had it all working with a custom label, but it broke when updating from umbraco 7.2.1 to 7.2.2 (nighlty build v.9).

    The only picker I now could get to work, was the XML checkboxpicker, but without custom labels. When using JSON chekcbox picker or using a custom label on the XML checkboxpicker, I got the same errors on JsonDataSourceApi/GetEditorItems and XMLDataSourceApi/GetEditorItems. 

    So i tried to update to nightly build v.18 but without success. Then I overwrote the ClientDependency.config with a clean out-of-the-box version, and all is now fixed and working!

    So it seems to be some error in the stack compiled by ClientDependency?

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 04, 2015 @ 11:27
    Hendy Racher
    0

    Hi, can't say that's an issue I've encountered, but good to hear it's all working again.

  • Zac 223 posts 575 karma points
    Feb 09, 2015 @ 11:58
    Zac
    0

    Hey Hendy,

    Were you able to reproduce the error with the http://beta.json-generator.com/KapqN6a JSON feed?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 09, 2015 @ 12:05
    Hendy Racher
    1

    Hi Zac,

    Yes I was - it's caused due to the fact that if the source JSON is an array, then it's expecting an array of strings - will hopefully have a fix for this pushed this week.

    Currently thinking along the lines of: (does this sound like a sensible approach ?)

    1) if an array of strings then use those strings for both the key / label (ignore any JsonPaths)

    2) if an array of objects of type: { 'key' : 1, 'label: 'item 1' } use these objects (ignore any JsonPaths)

    3) apply JsonPath (re-check condition 1, re-check condition 2)

    4) apply KeyJsonParth and LabelJsonPath

    HTH,

    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 10, 2015 @ 00:21
    Hendy Racher
    1

    Hi Zac,

    Both issues (locally served json without a file on the file system / handling an array of objects) should now be fixed.

    Here's a link to the latest NuGet build: https://www.myget.org/gallery/nupickers

    Hendy

  • Zac 223 posts 575 karma points
    Feb 11, 2015 @ 23:42
    Zac
    1

    Hi Hendy, yes that approach does indeed sound very sensible!

    Thank you for this, really. nuPickers is absolutely killer - loving the DotNetDataSource too. Between this and Archetype we have so much functionality these days with so little code.

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 12, 2015 @ 11:07
    Hendy Racher
    0

    Thanks :) hope it's all working now... (will have a full release out soon)

Please Sign in or register to post replies

Write your reply to:

Draft