locked
WebAPI not recognizing JSON generated by JSONCpp RRS feed

  • Question

  • I am building the following JSON using JsonCpp in a C++ app:

    PUT http://localhost/AvionBiometricRestService/api/Identify/ HTTP/1.1
    Accept: */*
    Content-Type: application/json
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;Windows NT 5.1)
    Host: localhost
    Content-Length: 2738
    Connection: Keep-Alive
    Pragma: no-cache
    
    { 
           " b i r d a t a "   :   " I B Q 3 A A Q B Z A I A A A B A N w A E A d 8 H C B o M J h k A A A A A A D c A B A E A A A A A A A A A A A A A A A A A A A A A A A A A A A g D A A B r \ r \ n e H M X C R 2 R s D K h p n J w W U m U T h c n I k e J g 3 K 1 t O f 0 5 p I l o 6 D O O d 0 A E Q O g m u Q O X Z K N p x v x m 1 R v Y U 5 / 4 a w 5 \ r \ n J o D I h N l 1 G V 7 d M j v v i O u l g a q c z L E k G 4 5 L Z C 9 k N E 3 o 9 B d i Y L f E d b L 4 1 f R d Z 8 G 9 Z 1 b 7 6 6 h 7 c l r D a 1 J u \ r \ n M U K v D D 3 g R h 0 B K 5 I o Y e L B D e f V v g s i u O Y v X s c R H C 2 E l D B s M 8 j C B h T G u 7 B E 1 n 3 g d O W L O r G v j A P T 2 u s 1 \ r \ n w L Q 7 j w Q V Z 7 D m 9 G t T q C K p f x S w m Z M a 3 F b T e j O T M + h h V O H N 1 i + Q n n 4 d 1 n X p n / G X f j n T x A 6 X l E + I q v B V \ r \ n L b 4 M / j Q U K l H y y 4 F H e U 3 s Y V h u / A j T P 2 U O 8 c + R 9 U 7 f d 1 G n m A 0 6 f 0 t o y w W h d 4 3 d h E n O 7 j Y x z 1 2 T a + a G \ r \ n 8 j y 7 l 4 Z B I q v p X R H Q G y L S G m Z 0 R g C 2 k m k v P K 7 Q W O + Y Y i m I 9 7 f + 2 a y f e L V J Z z 5 + d a d x G V a w a x 5 f N d V b \ r \ n / z 8 d o N J r x Y T n k k G F k L J i s n z y A I Z C / l 0 z x b 3 / 8 l y h 3 + x q 0 9 l l 3 K r z I 9 i 9 a s P y A G O N c r v 7 k q O e B O Y b \ r \ n P 5 d A y 4 q 1 b T g 0 x R S 2 Q v E H 9 l G o 6 r T U 3 M d C K Q C o s 3 0 D F 9 n e x 8 V Q c f r w 8 2 g t t H x H b D S k j P 9 9 J w 1 9 s 2 + s \ r \ n M D u S 6 S 4 j y + s w 4 q m n t N 2 Q f c 1 r H F u q / I b w X i 6 Y Q 3 k A R 4 G N z 9 Z E A q f e 8 y j X + d 9 5 U Y 5 L 6 9 m t H l D m X T D G \ r \ n u r a w b W m + w 3 J I Q a 0 k I S E d g j B Z N o a 1 E j 4 T M L b i r u a j S i 3 2 G 1 9 z v a Q q / S / f 6 i B Q y o W i 7 D X a / U X V W w g V \ r \ n X v C N A C A / c n 8 K x 5 e N T 7 k v a O 3 I u G k E 6 f p M e + W U j H a 8 c Y L y x 7 X 1 r l E 8 p 2 4 l x S e Y U x Z J g x R s l W / 9 J M b M \ r \ n J 1 z V 9 D S E 7 6 5 N s X Y m 4 G V G r 4 w L v l 5 3 I 3 S i X D v A K z z l 9 J 5 W J Y r X 5 8 + l d a h u 5 k 0 t l u l e M A 9 A r d K d I Z 2 e \ r \ n m T R k U T t T U J I t K q n H N l Y y 2 F A D A 9 y L 9 4 0 o 6 7 e a G n 7 u r V D v a v L m w l v Y l Z 8 O j L b c C 0 2 v F J Y z G 0 M j G Z 6 v \ r \ n n H O F a Y T u N 6 4 D D 0 w s 3 u l 8 i 2 e d q N g 8 P / B N j H K U 2 V I f G t F F I w A A A A A = " , 
           " e r r o r _ m e s s a g e "   :   t r u e , 
           " e r r o r _ r e t u r n e d "   :   0 , 
           " n u m b e r o f p e r s o n s r e t u r n e d "   :   0 , 
           " p e r s o n i d s "   :   t r u e , 
           " p r o d u c t o w n e r "   :   5 5 , 
           " p r o d u c t t y p e "   :   2 6 0 , 
           " s u b t y p e "   :   0 
     } 	 

    The WebAPI model looks like this:

    public class IdentifyModel { public int subtype { get; set; } public int productowner { get; set; } public int producttype { get; set; } public string birdata { get; set; } public string personids { get; set; } public int numberofpersonsreturned { get; set; } public string error_message { get; set; } public int error_returned { get; set; } }

    The request makes it to the controller method:

     public IHttpActionResult  Put(IdentifyModel value)
    {
        try
        {
               return Ok(value);
        }
        catch (Exception ex)
        {
           return BadRequest();
        }
    }

    However, the JSON is not getting parsed into the IdentifyModel as it is null

    Am I missing a step?



    • Edited by mohunt Wednesday, August 26, 2015 6:07 PM
    • Moved by Kristin Xie Thursday, August 27, 2015 6:12 AM
    Wednesday, August 26, 2015 6:02 PM

Answers

  • Hi mohunt,

    Web API

    http://forums.asp.net/1246.aspx/1?Web+API

    The above forum is where you should post.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Just Karl Thursday, August 27, 2015 9:40 PM
    • Marked as answer by Just Karl Friday, September 11, 2015 8:00 PM
    Thursday, August 27, 2015 6:12 AM

All replies

  • Hi mohunt,

    Web API

    http://forums.asp.net/1246.aspx/1?Web+API

    The above forum is where you should post.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Just Karl Thursday, August 27, 2015 9:40 PM
    • Marked as answer by Just Karl Friday, September 11, 2015 8:00 PM
    Thursday, August 27, 2015 6:12 AM
  • Hi,

    Try to set the content type to Content-Type: application/json; charset=utf-8

    If you have a [Serializable] attribute on the identitymodel class, remove it.

    Rgds MM


    PS: Please mark as answer if helpful. Thanks!

    Thursday, August 27, 2015 7:54 AM
  • Hello,

    I'd ask the project people:

    http://sourceforge.net/p/jsoncpp/discussion/483465

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Thursday, August 27, 2015 9:55 PM