locked
Json file i got jsonobject.how read jobject RRS feed

  • Question

  • User-148788041 posted
    Hi
    Json string
    ('Name':'sam',
    'Id':12,
    'Designation':'tl',
    'Location':'chennai'
    )
    Var jobject=newtonsoft.jsonconvert.deserializeobject(File.readalltext(json.txt);
    Jobject json=JObject.Parse(jobject).tostring();
    Here i have json object.
    I need to loop and display like
    Name='sam'&id=12&Designation='tl'&location='chennai'
    This i will pass with https://12.12/abovestring
    Friday, September 28, 2018 4:27 AM

All replies

  • User-893317190 posted

    Hi Guhananth,

    You could try the code below.

       var abc = "{'Name':'sam','Id':12,'Designation':'tl','Location':'chennai'}";
                var jobjct = Newtonsoft.Json.JsonConvert.DeserializeObject(abc);
                JObject jobj = JObject.Parse(abc);
                string str ="";
                foreach (var item in jobj)
                {
                    // use item.Value.Type==JTokenType.Integer to check whether item.Value is of type integer or not
                    str += item.Key + "=" + (item.Value.Type==JTokenType.Integer?item.Value:("'"+item.Value+"'"))+"&" ;
                }
                Response.Write(str.TrimEnd('&'));

    The result.

    Best regards,

    Ackerly Xu

    Friday, September 28, 2018 5:46 AM