2

i got some problem when i generate .json file from spring .json ,and i got this format

{ "models": [
    {
        "id":1,
        "modelName":"dfdsf",
        "created":{
            "userFullname":"demo",
            "time":"150301",
            "date":"20110208",
            "userId":"123"
        },
        "remark":"dsfdf",
        "updated":"~unique-id~1"
    },
    {
        "id":2,
        "modelName":"test",
        "created":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110210",
            "userId":"124"
        },
        "remark":"test",
        "updated":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110209",
            "userId":"test"
        }
    }
]}

first time i used JObject Parse for convert

JObject job = JObject.Parse(fullJson);

and the other hand i used jtoken to focus "models"

JToken jDetail = job["models"];

but the problem is {[{ xxx }]} it look like jarray i don't have any idea to convert it

i ever use JArray, JsonTextReader but it doesn't work.

could suggestion some? because if i pass this ll i set some value to object.

thank you for every idea.

2
  • 1
    I have something similar working via JavaScriptSerializer - or ar you tied to json.net? Commented Feb 10, 2011 at 9:58
  • yes ,i tried on vs2008 ( c# ) but have some idea,'ll post it ,Thank for suggest :) Commented Feb 11, 2011 at 3:47

1 Answer 1

2
string fullJson = File.ReadAllText("TextFile1.txt"); // for brevity
var job = JObject.Parse(fullJson);
var models = job.Value<JArray>("models");
Console.WriteLine(models[0]);

result:

{
  "id": 1,
  "modelName": "dfdsf",
  "created": {
    "userFullname": "demo",
    "time": "150301",
    "date": "20110208",
    "userId": "123"
  },
  "remark": "dsfdf",
  "updated": "~unique-id~1"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.